TRICK TO FIND BEST MODEL FOR YOUR DATA IN MACHINE LEARNING

Choosing the best model, along with appropriate data splitting and hyperparameter tuning of model will help you to find best model with best parameters for your data in machine learning.
Grid search CV library of sklearn can help you to do exactly that.

EXAMPLE

The example below demonstrates how to find the best model and its parameters for the digits dataset of sklearn.

  • First pandas and numpy are imported, as these are helpful in performing various tasks that we need to do.
  • Then datasets library from sklearn is imported.
  • Then from datasets library ,digits data is imported .
  • This data contains data about hand written numbers with according to pixel values of images. In this example we will try to find best model and its parameters for this data.
  • Then we used .keys function in order to get overview of the digits data.
  • Now we imported all the models of classifications as our target value is of classification type.
  • And then we created a dictionary which contains models as well as there parameters with different values that we need to try in grid search CV.
  • We the help of for loop and .items function we extracted model names, model functions and there parameters on by one these in grid search CV and we found the best accuracy scores for each of the model type along with best parameters combinations. Then we added the best accuracy scores, model names and best model parameters in scores list in order to review them.

  • In the end we found that SVM classifier performs the best for the above dataset with parameters.

Conclusion:

In machine learning finding the best conditions is not like that by seeing the data you can predict on your own that this model will be the best, its more like a hit and trial technique. You need to try all the possible algorithms that can be applied and after that also need to find the best combinations of the paramaters of these algorithms in order to find the best conditions for your data. And in order to do that easily GridSearchCV can help you.


WANT TO WRITE BLOG CONTACT US NOW!!

CONTACT NOW
Shashank
@Shashank

Student|Data Science enthusiast

Contact Us