How it works...
The dataset is split into k parts, and k-1 parts are used for training and 1 for testing. In the testing part, the relevant metric is calculated (in this case, it's accuracy). This is done for each combination of hyperparameters that we have (in this case, we only have one of them). Finally, the model is retrained using the full dataset and those very same hyperparameters.
Even though this example works with a classification model, the same can be done for regression models as well (in this case, we need to adjust the metric accordingly).
The accuracy is usually a bad metric when the data is imbalanced, since models that work well for the most frequent class will be assumed to be better. In those cases, metrics such as the ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access