Generalization Technique for ML models

Ever wondered about the term “Generalization” for ML models? Generalization in Machine Learning means, the model which you built using your data, gives better results on testing data compared to the training data.

How to achieve generalization? By simply changing the random state at the time of splitting the data into training and validation data you can achieve generalization.

Let’s take an example of the iris dataset. Iris dataset has features as sepal length, sepal width, petal length, petal width. The labels are Setosa, Versicolor, and Virginica. It has 150 rows.

Big Data Jobs

Just loop random state in a range from 0 to 99 and calculate the train and test score of the models created. In the loop specify the condition if the score for test data is better than training data, then append the random state, training score, and testing score in a list called scores.

The models generated with the random states appended in the list scores are all generalized models as they perform better for testing data set compared to training data set. If you are doing a regression problem you can use other metrics like RMSE and this time the goal will be testing error should be less than the training error. Since it is a classification problem we will be using the accuracy metric.

Trending AI Articles:

1. Write Your First AI Project in 15 Minutes

2. Generating neural speech synthesis voice acting using xVASynth

3. Top 5 Artificial Intelligence (AI) Trends for 2021

4. Why You’re Using Spotify Wrong

Sort scores in descending order to get the generalized model with the highest accuracy on testing data.

With random state 0, I am getting the highest accuracy on testing data, so I will be selecting the model with random state 0.

The GitHub link for this tutorial is as below:

pratikskarnik/Generalization_Technique

Don’t forget to give us your ? !


Generalization Technique for ML models was originally published in Becoming Human: Artificial Intelligence Magazine on Medium, where people are continuing the conversation by highlighting and responding to this story.

Via https://becominghuman.ai/generalization-technique-for-ml-models-ed6ba666d171?source=rss—-5e5bef33608a—4

source https://365datascience.weebly.com/the-best-data-science-blog-2020/generalization-technique-for-ml-models

Published by 365Data Science

365 Data Science is an online educational career website that offers the incredible opportunity to find your way into the data science world no matter your previous knowledge and experience. We have prepared numerous courses that suit the needs of aspiring BI analysts, Data analysts and Data scientists. We at 365 Data Science are committed educators who believe that curiosity should not be hindered by inability to access good learning resources. This is why we focus all our efforts on creating high-quality educational content which anyone can access online.

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Design a site like this with WordPress.com
Get started