MulaiMulai sekarang secara gratis

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.

Latihan ini adalah bagian dari kursus

Machine Learning with Tree-Based Models in Python

Lihat Kursus

Petunjuk latihan

  • Import mean_squared_error as MSE from sklearn.metrics.
  • Fit dt to the training set.
  • Predict dt's training set labels and assign the result to y_pred_train.
  • Evaluate dt's training set RMSE and assign it to RMSE_train.

Latihan interaktif praktis

Cobalah latihan ini dengan menyelesaikan kode contoh berikut.

# 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))
Edit dan Jalankan Kode