Modeling Summary
You have now learned how to build a model, integrate it into a pipeline, and tune hyperparameters. Two evaluation methods are also covered: the train-test split and cross-validation.
The next step is to combine model evaluation with hyperparameter tuning using GridSearchCV
or RandomizedSearchCV
.
Since our dataset is tiny, we will use the GridSearchCV
, but everything said below also applies to a RandomizedSearchCV
.
The objective is to obtain the highest cross-validation score on the dataset, since cross-validation is more stable and less dependent on how the data is split than the train-test approach.
GridSearchCV
is specifically designed for this purpose: it identifies the hyperparameters that achieve the best cross-validation score, producing a fine-tuned model that performs optimally on the training data.
The .best_score_
attribute stores the highest cross-validation score found during the search.
The best hyperparameters for one specific dataset may not necessarily be the best overall. If new data is added, the optimal hyperparameters might change.
Consequently, the .best_score_
achieved might be higher than the performance on completely unseen data, as the hyperparameters might not generalize as well beyond the training dataset.
Typically, the dataset is first split into training and test sets. Cross-validation is then applied to the training set to fine-tune the model and identify the best configuration. Finally, the optimized model is evaluated on the test set, which contains entirely unseen data, to assess its real-world performance.
To summarize, the full workflow consists of:
- Preprocessing the data;
- Splitting the dataset into training and test sets;
- Using cross-validation on the training set to find the best-performing model;
- Evaluating that model on the test set.
The third step usually involves testing multiple algorithms and tuning their hyperparameters to identify the best option. For simplicity, only a single algorithm was used in this course.
Before moving on to the final challenge, it's important to note that cross-validation isn't the only method for fine-tuning models. As datasets grow larger, computing cross-validation scores becomes more time-consuming, and the regular train-test split offers more stability due to the increased size of the test set.
Consequently, large datasets are often divided into three sets: a training set, a validation set, and a test set. The model is trained on the training set and evaluated on the validation set to select the model or hyperparameters that perform best.
This selection uses the validation set scores instead of cross-validation scores. Finally, the chosen model is assessed on the test set, which consists of completely unseen data, to verify its performance.
The penguins dataset is small, with only 342 instances. Because of this limited size, the cross-validation score will be used for evaluation in the next chapter.
Thanks for your feedback!
Ask AI
Ask AI
Ask anything or try one of the suggested questions to begin our chat
Awesome!
Completion rate improved to 3.13
Modeling Summary
Swipe to show menu
You have now learned how to build a model, integrate it into a pipeline, and tune hyperparameters. Two evaluation methods are also covered: the train-test split and cross-validation.
The next step is to combine model evaluation with hyperparameter tuning using GridSearchCV
or RandomizedSearchCV
.
Since our dataset is tiny, we will use the GridSearchCV
, but everything said below also applies to a RandomizedSearchCV
.
The objective is to obtain the highest cross-validation score on the dataset, since cross-validation is more stable and less dependent on how the data is split than the train-test approach.
GridSearchCV
is specifically designed for this purpose: it identifies the hyperparameters that achieve the best cross-validation score, producing a fine-tuned model that performs optimally on the training data.
The .best_score_
attribute stores the highest cross-validation score found during the search.
The best hyperparameters for one specific dataset may not necessarily be the best overall. If new data is added, the optimal hyperparameters might change.
Consequently, the .best_score_
achieved might be higher than the performance on completely unseen data, as the hyperparameters might not generalize as well beyond the training dataset.
Typically, the dataset is first split into training and test sets. Cross-validation is then applied to the training set to fine-tune the model and identify the best configuration. Finally, the optimized model is evaluated on the test set, which contains entirely unseen data, to assess its real-world performance.
To summarize, the full workflow consists of:
- Preprocessing the data;
- Splitting the dataset into training and test sets;
- Using cross-validation on the training set to find the best-performing model;
- Evaluating that model on the test set.
The third step usually involves testing multiple algorithms and tuning their hyperparameters to identify the best option. For simplicity, only a single algorithm was used in this course.
Before moving on to the final challenge, it's important to note that cross-validation isn't the only method for fine-tuning models. As datasets grow larger, computing cross-validation scores becomes more time-consuming, and the regular train-test split offers more stability due to the increased size of the test set.
Consequently, large datasets are often divided into three sets: a training set, a validation set, and a test set. The model is trained on the training set and evaluated on the validation set to select the model or hyperparameters that perform best.
This selection uses the validation set scores instead of cross-validation scores. Finally, the chosen model is assessed on the test set, which consists of completely unseen data, to verify its performance.
The penguins dataset is small, with only 342 instances. Because of this limited size, the cross-validation score will be used for evaluation in the next chapter.
Thanks for your feedback!