Aan de slagGa gratis aan de slag

Implement cross_val_score()

Your company has created several new candies to sell, but they are not sure if they should release all five of them. To predict the popularity of these new candies, you have been asked to build a regression model using the candy dataset. Remember that the response value is a head-to-head win-percentage against other candies.

Before you begin trying different regression models, you have decided to run cross-validation on a simple random forest model to get a baseline error to compare with any future results.

Deze oefening maakt deel uit van de cursus

Model Validation in Python

Cursus bekijken

Oefeninstructies

  • Fill in cross_val_score().
    • Use X_train for the training data, and y_train for the response.
    • Use rfc as the model, 10-fold cross-validation, and mse for the scoring function.
  • Print the mean of the cv results.

Praktische interactieve oefening

Probeer deze oefening eens door deze voorbeeldcode in te vullen.

rfc = RandomForestRegressor(n_estimators=25, random_state=1111)
mse = make_scorer(mean_squared_error)

# Set up cross_val_score
cv = cross_val_score(estimator=____,
                     X=____,
                     y=____,
                     cv=____,
                     scoring=____)

# Print the mean error
print(cv.____())
Code bewerken en uitvoeren