Using Learning Curves - ML - GeeksforGeeks (2024)

    • AI ML DS
    • Data Science
    • Data Analysis
    • Data Visualization
    • Machine Learning
    • Deep Learning
    • NLP
    • Computer Vision
    • Artificial Intelligence
    • AI ML DS Interview Series
    • AI ML DS Projects series
    • Data Engineering
    • Web Scrapping

    Open In App

    Last Updated : 17 Jul, 2020

    Improve

    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.

    Bias:
    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.

    Variance:
    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.

    Code:

    #Importing Required Libraries and Modules

    import numpy as np

    import matplotlib.pyplot as plt

    from sklearn.neighbors import KNeighborsClassifier

    from sklearn.datasets import load_digits

    from sklearn.model_selection import learning_curve

    # Load data set

    dataset = load_digits()

    # X contains data and y contains labels

    X, y = dataset.data, dataset.target

    # Obtain scores from learning curve function

    # cv is the number of folds while performing Cross Validation

    sizes, training_scores, testing_scores = learning_curve(KNeighborsClassifier(), X, y, cv=10, scoring='accuracy', train_sizes=np.linspace(0.01, 1.0, 50))

    # Mean and Standard Deviation of training scores

    mean_training = np.mean(training_scores, axis=1)

    Standard_Deviation_training = np.std(training_scores, axis=1)

    # Mean and Standard Deviation of testing scores

    mean_testing = np.mean(testing_scores, axis=1)

    Standard_Deviation_testing = np.std(testing_scores, axis=1)

    # dotted blue line is for training scores and green line is for cross-validation score

    plt.plot(sizes, mean_training, '--', color="b", label="Training score")

    plt.plot(sizes, mean_testing, color="g", label="Cross-validation score")

    # Drawing plot

    plt.title("LEARNING CURVE FOR KNN Classifier")

    plt.xlabel("Training Set Size"), plt.ylabel("Accuracy Score"), plt.legend(loc="best")

    plt.tight_layout()

    plt.show()

    Output:


    Using Learning Curves - ML - GeeksforGeeks (1)

    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.

    Conclusion:
    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.



    alokesh985

    Improve

    Next Article

    Machine Learning in C++

    Please Login to comment...

    Similar Reads

    Python Bokeh - Plotting Quadratic Curves on a Graph Bokeh is a Python interactive data visualization. It renders its plots using HTML and JavaScript. It targets modern web browsers for presentation providing elegant, concise construction of novel graphics with high-performance interactivity. Bokeh can be used to plot quadratic curves on a graph. Plotting quadratic curves on a graph can be done using 2 min read Calibration Curves Generally, for any classification problem, we predict the class value that has the highest probability of being the true class label. However, sometimes, we want to predict the probabilities of a data instance belonging to each class label. For example, say we are building a model to classify fruits and we have three class labels: apples, oranges, 3 min read ML | Reinforcement Learning Algorithm : Python Implementation using Q-learning Prerequisites: Q-Learning technique. Reinforcement Learning is a type of Machine Learning paradigms in which a learning algorithm is trained not on preset data but rather based on a feedback system. These algorithms are touted as the future of Machine Learning as these eliminate the cost of collecting and cleaning the data. In this article, we are 6 min read Automated Machine Learning for Supervised Learning using R Automated Machine Learning (AutoML) is an approach that aims to automate various stages of the machine learning process, making it easier for users with limited machine learning expertise to build high-performing models. AutoML is particularly useful in supervised learning, where you have labeled data and want to create models that can make predict 8 min read Introduction to Multi-Task Learning(MTL) for Deep Learning Multi-Task Learning (MTL) is a type of machine learning technique where a model is trained to perform multiple tasks simultaneously. In deep learning, MTL refers to training a neural network to perform multiple tasks by sharing some of the network's layers and parameters across tasks. In MTL, the goal is to improve the generalization performance of 6 min read Artificial intelligence vs Machine Learning vs Deep Learning Nowadays many misconceptions are there related to the words machine learning, deep learning, and artificial intelligence (AI), most people think all these things are the same whenever they hear the word AI, they directly relate that word to machine learning or vice versa, well yes, these things are related to each other but not the same. Let's see 4 min read Difference Between Artificial Intelligence vs Machine Learning vs Deep Learning Artificial Intelligence is basically the mechanism to incorporate human intelligence into machines through a set of rules(algorithm). AI is a combination of two words: "Artificial" meaning something made by humans or non-natural things and "Intelligence" meaning the ability to understand or think accordingly. Another definition could be that "AI is 14 min read Need of Data Structures and Algorithms for Deep Learning and Machine Learning Deep Learning is a field that is heavily based on Mathematics and you need to have a good understanding of Data Structures and Algorithms to solve the mathematical problems optimally. Data Structures and Algorithms can be used to determine how a problem is represented internally or how the actual storage pattern works & what is happening under 6 min read Fusion Learning - The One Shot Federated Learning Introduction Machine Learning has improved our lives significantly. Right from the intelligent chatbots to autonomous cars. The main ingredient which improves these models to perform beyond expectation is data. With the digitization and increased popularity of IoT, more and more people have devices that are generating immense amounts of quality dat 5 min read Machine Learning - Learning VS Designing In this article, we will learn about Learning and Designing and what are the main differences between them. In Machine learning, the term learning refers to any process by which a system improves performance by using experience and past data. It is kind of an iterative process and every time the system gets improved though one may not see a drastic 3 min read

    Article Tags :

    • AI-ML-DS
    • Machine Learning
    • AI-ML-DS With Python

    Practice Tags :

    • Machine Learning

    We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy

    Using Learning Curves - ML - GeeksforGeeks (3)

    Using Learning Curves - ML - GeeksforGeeks (2024)
    Top Articles
    Primeval Essence Wow
    The Radical Calling (Mark 1:16-20)
    Spasa Parish
    Rentals for rent in Maastricht
    159R Bus Schedule Pdf
    Sallisaw Bin Store
    Black Adam Showtimes Near Maya Cinemas Delano
    Espn Transfer Portal Basketball
    Pollen Levels Richmond
    11 Best Sites Like The Chive For Funny Pictures and Memes
    Things to do in Wichita Falls on weekends 12-15 September
    Craigslist Pets Huntsville Alabama
    Paulette Goddard | American Actress, Modern Times, Charlie Chaplin
    What's the Difference Between Halal and Haram Meat & Food?
    R/Skinwalker
    Rugged Gentleman Barber Shop Martinsburg Wv
    Jennifer Lenzini Leaving Ktiv
    Justified - Streams, Episodenguide und News zur Serie
    Epay. Medstarhealth.org
    Olde Kegg Bar & Grill Portage Menu
    Cubilabras
    Half Inning In Which The Home Team Bats Crossword
    Amazing Lash Bay Colony
    Juego Friv Poki
    Dirt Devil Ud70181 Parts Diagram
    Truist Bank Open Saturday
    Water Leaks in Your Car When It Rains? Common Causes & Fixes
    What’s Closing at Disney World? A Complete Guide
    New from Simply So Good - Cherry Apricot Slab Pie
    Drys Pharmacy
    modelo julia - PLAYBOARD
    Poker News Views Gossip
    Abby's Caribbean Cafe
    Joanna Gaines Reveals Who Bought the 'Fixer Upper' Lake House and Her Favorite Features of the Milestone Project
    Tri-State Dog Racing Results
    Navy Qrs Supervisor Answers
    Trade Chart Dave Richard
    Lincoln Financial Field Section 110
    Free Stuff Craigslist Roanoke Va
    Stellaris Resolution
    Wi Dept Of Regulation & Licensing
    Pick N Pull Near Me [Locator Map + Guide + FAQ]
    Crystal Westbrooks Nipple
    Ice Hockey Dboard
    Über 60 Prozent Rabatt auf E-Bikes: Aldi reduziert sämtliche Pedelecs stark im Preis - nur noch für kurze Zeit
    Wie blocke ich einen Bot aus Boardman/USA - sellerforum.de
    Infinity Pool Showtimes Near Maya Cinemas Bakersfield
    Dermpathdiagnostics Com Pay Invoice
    How To Use Price Chopper Points At Quiktrip
    Maria Butina Bikini
    Busted Newspaper Zapata Tx
    Latest Posts
    Article information

    Author: Kelle Weber

    Last Updated:

    Views: 6182

    Rating: 4.2 / 5 (53 voted)

    Reviews: 84% of readers found this page helpful

    Author information

    Name: Kelle Weber

    Birthday: 2000-08-05

    Address: 6796 Juan Square, Markfort, MN 58988

    Phone: +8215934114615

    Job: Hospitality Director

    Hobby: tabletop games, Foreign language learning, Leather crafting, Horseback riding, Swimming, Knapping, Handball

    Introduction: My name is Kelle Weber, I am a magnificent, enchanting, fair, joyous, light, determined, joyous person who loves writing and wants to share my knowledge and understanding with you.