cross_val_score
The cross_val_score()
function is available in sklearn.model_selection
. Up until this point, you have learned how to create cross-validation datasets in a loop. If you made use of that approach, you would need to keep track of all of the models that you are training and evaluating inside of that loop.
cross_val_score
takes care of the following:
- Creating cross-validation datasets
- Training models by fitting them to the training data
- Evaluating the models on the validation data
- Returning a list of the R2 score of each model that is trained
For all of the preceding actions to happen, you will need to provide the following inputs:
- An instance of an estimator (for example,
LinearRegression
) - The original dataset
- The number of splits to create (which is also the number of models that will be trained and evaluated)
Exercise 7.05: Getting the Scores from Five-Fold Cross-Validation
The goal of this exercise is to create...