A learning model of a Machine Learning model shows how the error in the prediction of a Machine Learning model changes as the size of the training set increases or decreases.
Before we continue, we must first understand what variance and bias mean in the Machine Learning model.
It is basically nothing but the difference between the average prediction of a model and the correct value of the prediction. Models with high bias make a lot of assumptions about the training data. This leads to over-simplification of the model and may cause a high error on both the training and testing sets. However, this also makes the model faster to learn and easy to understand. Generally, linear model algorithms like Linear Regression have a high bias.
It is the amount a model’s prediction will change if the training data is changed. Ideally, a machine learning model should not vary too much with a change in training sets i.e., the algorithm should be good at picking up important details about the data, regardless of the data itself. Example of algorithms with high variance is Decision Trees, Support Vector Machines (SVM).
Ideally, we would want a model with low variance as well as low bias. To achieve lower bias, we need more training data but with higher training data, the variance of the model will increase. So, we have to strike a balance between the two. This is called the bias-variance trade-off.
A learning curve can help to find the right amount of training data to fit our model with a good bias-variance trade-off. This is why learning curves are so important.
Now that we understand the bias-variance trade-off and why a learning curve is important, we will now learn how to use learning curves in Python using the scikit-learn library of Python.
Implementation of Learning Curves in Python:
For the sake of this example, we will be using the very popular, ‘Digit’ data set. For more information on this data set, you can refer to the link below :https://scikit-learn.org/stable/auto_examples/datasets/plot_digits_last_image
We will use a k-Nearest Neighbour classifier for this example. We will also perform 10-fold cross-validation for obtaining validation scores to plot on the graph.
From the curve, we can clearly see that as the size of the training set increases, the training score curve and the cross-validation score curve converge. The cross-validation accuracy increases as we add more training data. So adding training data is useful in this case. Since the training score is very accurate, this indicates low bias and high variance. So this model also begins overfitting the data because the cross-validation score is relatively lower and increases very slowly as the size of the training set increases.
Learning Curves are a great diagnostic tool to determine bias and variance in a supervised machine learning algorithm. In this article, we have learnt what learning curves and how they are implemented in Python.
- Make filled polygons between two curves in Python using Matplotlib
- Make filled polygons between two horizontal curves in Python using Matplotlib
- How to plot Andrews curves using Pandas in Python?
- Rhodonea Curves and Maurer Rose in Python
- Plotting polar curves in Python
- Python Bokeh - Plotting Quadratic Curves on a Graph
- Calibration Curves
- ML | Reinforcement Learning Algorithm : Python Implementation using Q-learning
- Learning Model Building in Scikit-learn : A Python Machine Learning Library
- How to Start Learning Machine Learning?
- Prediction of Wine type using Deep Learning
- Avengers Endgame and Deep learning | Image Caption Generation using the Avengers EndGames Characters
- Implementing Deep Q-Learning using Tensorflow
- Deploy Machine Learning Model using Flask
- Using Google Cloud Function to generate data for Machine Learning model
- Human Activity Recognition - Using Deep Learning Model
- Machine Learning Computing at the edge using model artifacts
- Machine Learning Workflow using Pycaret
- Deploy a Machine Learning Model using Streamlit Library
- Intrusion Detection System Using Machine Learning Algorithms