Evaluate the training error
You'll now evaluate the training set RMSE achieved by the regression tree dt that you instantiated in a previous exercise.
In addition to dt, X_train and y_train are available in your workspace.
Note that in scikit-learn, the MSE of a model can be computed as follows:
MSE_model = mean_squared_error(y_true, y_predicted)
where we use the function mean_squared_error from the metrics module and pass it the true labels y_true as a first argument, and the predicted labels from the model y_predicted as a second argument.
This exercise is part of the course
Machine Learning with Tree-Based Models in Python
Exercise instructions
- Import
mean_squared_errorasMSEfromsklearn.metrics. - Fit
dtto the training set. - Predict
dt's training set labels and assign the result toy_pred_train. - Evaluate
dt's training set RMSE and assign it toRMSE_train.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Import mean_squared_error from sklearn.metrics as MSE
____
# Fit dt to the training set
____.____(____, ____)
# Predict the labels of the training set
____ = ____.____(____)
# Evaluate the training set RMSE of dt
____ = (____(____, ____))**(___)
# Print RMSE_train
print('Train RMSE: {:.2f}'.format(RMSE_train))