11-08-2024
Machine Learning
Hyperparameter Tuning
Hyperparameter Tuning
• Models have internal and external parameters.
• External parameters are called hyperparameters that need to be set
for model to perform optimally
• Internal parameters are taken care by the model itself.
• Hyperparameters generally control the over-fitting and under-fitting
of the model. Optimal hyperparameters often differ for different
datasets.
• For each proposed hyperparameter setting, the model is evaluated
• The hyperparameters that give the best model are selected
1
11-08-2024
Hyperparameter Tuning
• Simple linear regression does not have any hyperparameters
• Other linear regressions such as Lasso, Ridge, and Elastic Net have
hyperparameters
• All other machine learnings algorithms except simple linear
regression have hyperparameters
• For example: Learning rate , a hyperparameter, needs to be set in
such a way that algorithm reaches optimal solution.
Hyperparameters Search
• Grid Search: It picks a grid of hyperparameter values and evaluates each of
them, one at a time. Min and max of each hyperparameter must be defined,
basing on the educated guess.
• Method: GridSearchCV
• Random Search: It chooses the hyperparameter sample combinations
randomly from the grid space, in contrast to Grid Search that tries with every
possible combination supplied to the algorithm. It is very effective in practice
as it reduces computational time but there is not guarantee that we will find
the best result like Grid Search.
• Method: RandomizedSearchCV
• URL: [Link]
• Complete List: [Link]
2
11-08-2024
Cross Validation (CV)
• We train algorithm on training data and check performance on unseen
data which is testing data
• Best model: learnt well and not getting to much noise
• To build robust model, cross validation needs to be performed
• CV is a technique in which model is trained on the subset of the dataset
and thereafter is evaluated on the complimentary subset of the dataset
• K-fold Cross Validation, K-fold Time-Series Cross Validation
• Full List: [Link]
Cross Validation (CV)
• 5-fold Cross Validation
3
11-08-2024
Cross Validation (CV)
• 4-fold Time-Series Cross Validation