Registrations Closing Soon for DevOps Certification Training by CloudxLab | Registrations Closing in

  Enroll Now

End to End ML Project - Train a Decision Tree model

Now that we have prepared the data, we will train a Decision Tree model on that data and see how it performs. Since this is a regression problem, we will use the DecisionTreeRegressor class from Scikit-learn.

INSTRUCTIONS
  • Import the DecisionTreeRegressor class from Scikit-learn

    from sklearn.tree import <<your code goes here>>
    
  • Now let's train the DecisionTreeRegressor

    tree_reg = DecisionTreeRegressor(random_state=42)
    tree_reg.fit(housing_prepared, housing_labels)
    
  • To evaluate the performance of our model, we will import the mean_squared_error class from Scikit-learn

    from sklearn.metrics import <<your code goes here>>
    
  • Now let's predict using our model using the predict method

    housing_predictions = tree_reg.<<your code goes here>>(housing_prepared)
    
  • Finally, let's evaluate our model

    tree_mse = mean_squared_error(housing_labels, housing_predictions)
    tree_rmse = np.sqrt(tree_mse)
    tree_rmse
    

    If your trained your model correctly, the rmse would come to 0.0. This means that our model is overfitting. How to resolve this issue? We will come to that in a bit, but before that we will train a Random Forest model.


No hints are availble for this assesment

Answer is not availble for this assesment


Note - Having trouble with the assessment engine? Follow the steps listed here

Loading comments...