How to plot multiple learning curve from different model on the same graph?How do I return multiple values from a function?multiple graphs from a loop in one single plot - PythonHow to Plot PR-Curve Over 10 folds of Cross Validation in Scikit-LearnVery low test score result in sklearn diabetes dataset on plotting the learning curve with decision treeIn case of logistic regression, how should I interpret this learning curve between cost and number of examples?How to plot a Line Graph in Java using dataset from a text file?Changing variables in a function to create multiple plots on same axesWhat does this learning curve show ? And how to handle non representativity of a sample?Binary classification, precision-recall curve and thresholdsHow to plot the average of ROC curves?

The meaning of "offing" in "an agreement in the offing"

Why does PAUSE key have a long make code and no break code?

When did computers stop checking memory on boot?

Bit floating sequence

k times Fold with 3 changing extra variables

How invisible hand adjusts stock prices if company is listed on multiple exchanges, under multiple currencies, and one of the currencies plunges?

How do German speakers decide what should be on the left side of the verb?

After a few interviews, What should I do after told to wait?

How can I hint that my character isn't real?

Solving an inequation

How to run NPCs with complicated mechanics?

I won a car in a poker game. How is that taxed in Canada?

How do we create our own symbolisms?

Contractor cut joist hangers to make them fit

What's the biggest difference between these two photos?

More than three domains hosted on the same IP address

Can you pop microwave popcorn on a stove?

Are fast interviews red flags?

Why are some hotels asking you to book through Booking.com instead of matching the price at the front desk?

Did the Byzantines ever attempt to move their capital to Rome?

Examples where "thin + thin = nice and thick"

Python implementation of atoi

How to improvise or make pot grip / pot handle

How to restrain your dragon?



How to plot multiple learning curve from different model on the same graph?


How do I return multiple values from a function?multiple graphs from a loop in one single plot - PythonHow to Plot PR-Curve Over 10 folds of Cross Validation in Scikit-LearnVery low test score result in sklearn diabetes dataset on plotting the learning curve with decision treeIn case of logistic regression, how should I interpret this learning curve between cost and number of examples?How to plot a Line Graph in Java using dataset from a text file?Changing variables in a function to create multiple plots on same axesWhat does this learning curve show ? And how to handle non representativity of a sample?Binary classification, precision-recall curve and thresholdsHow to plot the average of ROC curves?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








1















I have few models that I have trained, and wanted to plot the learning curve of each model on a single graph



I tried this, and worked. But it felt redundant.



train_sizes, train_scores, test_scores = learning_curve(model, 
train_dummies,
y,
cv=5,
scoring='neg_mean_squared_error')


Because I need to repeat the train_scores and test_scores for each model.



I tried it using for loop.



First , I saved the models in an array.



arr = [m1,m2,m3]


But when I started the for loop, it only produced a single line on the graph.



for i in arr:
train_sizes, train_scores, test_scores = learning_curve(i,
train_dummies,
y,
cv=5,
scoring='neg_mean_squared_error')
train_mean = np.mean(train_scores, axis=1)
train_std = np.std(train_scores, axis=1)

test_mean = np.mean(test_scores, axis=1)
test_std = np.std(test_scores, axis=1)


plt.plot(train_sizes, test_mean, label="Cross-validation score")


Here is the desired output



Desired output



Will someone show me what am I lacking ? Your time is deeply appreciated.










share|improve this question





















  • 2





    are you aware that test_mean is not defined within the for loop?

    – SamProell
    Mar 28 at 7:16











  • @SamProell thanks for pointing. left it out on purpose. :)

    – Iqlaas Ismail
    Mar 28 at 9:34






  • 2





    i can't spot anything wrong with what you are doing.. This works for me: gist.github.com/SamProell/59d1d4fac1e319b3d19e98335058fc3f

    – SamProell
    Mar 28 at 10:01











  • @SamProell, thanks. My mistake was, iterating the variable instead of the modelling itself. I saved model_1 earlier, and iterate using model_1. I guess the coding could not pickup what is model_1 and thats why it plotted the graph separately. If you put your gist here, I would gladly star it.

    – Iqlaas Ismail
    Mar 31 at 1:33


















1















I have few models that I have trained, and wanted to plot the learning curve of each model on a single graph



I tried this, and worked. But it felt redundant.



train_sizes, train_scores, test_scores = learning_curve(model, 
train_dummies,
y,
cv=5,
scoring='neg_mean_squared_error')


Because I need to repeat the train_scores and test_scores for each model.



I tried it using for loop.



First , I saved the models in an array.



arr = [m1,m2,m3]


But when I started the for loop, it only produced a single line on the graph.



for i in arr:
train_sizes, train_scores, test_scores = learning_curve(i,
train_dummies,
y,
cv=5,
scoring='neg_mean_squared_error')
train_mean = np.mean(train_scores, axis=1)
train_std = np.std(train_scores, axis=1)

test_mean = np.mean(test_scores, axis=1)
test_std = np.std(test_scores, axis=1)


plt.plot(train_sizes, test_mean, label="Cross-validation score")


Here is the desired output



Desired output



Will someone show me what am I lacking ? Your time is deeply appreciated.










share|improve this question





















  • 2





    are you aware that test_mean is not defined within the for loop?

    – SamProell
    Mar 28 at 7:16











  • @SamProell thanks for pointing. left it out on purpose. :)

    – Iqlaas Ismail
    Mar 28 at 9:34






  • 2





    i can't spot anything wrong with what you are doing.. This works for me: gist.github.com/SamProell/59d1d4fac1e319b3d19e98335058fc3f

    – SamProell
    Mar 28 at 10:01











  • @SamProell, thanks. My mistake was, iterating the variable instead of the modelling itself. I saved model_1 earlier, and iterate using model_1. I guess the coding could not pickup what is model_1 and thats why it plotted the graph separately. If you put your gist here, I would gladly star it.

    – Iqlaas Ismail
    Mar 31 at 1:33














1












1








1








I have few models that I have trained, and wanted to plot the learning curve of each model on a single graph



I tried this, and worked. But it felt redundant.



train_sizes, train_scores, test_scores = learning_curve(model, 
train_dummies,
y,
cv=5,
scoring='neg_mean_squared_error')


Because I need to repeat the train_scores and test_scores for each model.



I tried it using for loop.



First , I saved the models in an array.



arr = [m1,m2,m3]


But when I started the for loop, it only produced a single line on the graph.



for i in arr:
train_sizes, train_scores, test_scores = learning_curve(i,
train_dummies,
y,
cv=5,
scoring='neg_mean_squared_error')
train_mean = np.mean(train_scores, axis=1)
train_std = np.std(train_scores, axis=1)

test_mean = np.mean(test_scores, axis=1)
test_std = np.std(test_scores, axis=1)


plt.plot(train_sizes, test_mean, label="Cross-validation score")


Here is the desired output



Desired output



Will someone show me what am I lacking ? Your time is deeply appreciated.










share|improve this question
















I have few models that I have trained, and wanted to plot the learning curve of each model on a single graph



I tried this, and worked. But it felt redundant.



train_sizes, train_scores, test_scores = learning_curve(model, 
train_dummies,
y,
cv=5,
scoring='neg_mean_squared_error')


Because I need to repeat the train_scores and test_scores for each model.



I tried it using for loop.



First , I saved the models in an array.



arr = [m1,m2,m3]


But when I started the for loop, it only produced a single line on the graph.



for i in arr:
train_sizes, train_scores, test_scores = learning_curve(i,
train_dummies,
y,
cv=5,
scoring='neg_mean_squared_error')
train_mean = np.mean(train_scores, axis=1)
train_std = np.std(train_scores, axis=1)

test_mean = np.mean(test_scores, axis=1)
test_std = np.std(test_scores, axis=1)


plt.plot(train_sizes, test_mean, label="Cross-validation score")


Here is the desired output



Desired output



Will someone show me what am I lacking ? Your time is deeply appreciated.







python matplotlib machine-learning graph






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 28 at 9:33







Iqlaas Ismail

















asked Mar 28 at 6:33









Iqlaas IsmailIqlaas Ismail

2354 silver badges15 bronze badges




2354 silver badges15 bronze badges










  • 2





    are you aware that test_mean is not defined within the for loop?

    – SamProell
    Mar 28 at 7:16











  • @SamProell thanks for pointing. left it out on purpose. :)

    – Iqlaas Ismail
    Mar 28 at 9:34






  • 2





    i can't spot anything wrong with what you are doing.. This works for me: gist.github.com/SamProell/59d1d4fac1e319b3d19e98335058fc3f

    – SamProell
    Mar 28 at 10:01











  • @SamProell, thanks. My mistake was, iterating the variable instead of the modelling itself. I saved model_1 earlier, and iterate using model_1. I guess the coding could not pickup what is model_1 and thats why it plotted the graph separately. If you put your gist here, I would gladly star it.

    – Iqlaas Ismail
    Mar 31 at 1:33













  • 2





    are you aware that test_mean is not defined within the for loop?

    – SamProell
    Mar 28 at 7:16











  • @SamProell thanks for pointing. left it out on purpose. :)

    – Iqlaas Ismail
    Mar 28 at 9:34






  • 2





    i can't spot anything wrong with what you are doing.. This works for me: gist.github.com/SamProell/59d1d4fac1e319b3d19e98335058fc3f

    – SamProell
    Mar 28 at 10:01











  • @SamProell, thanks. My mistake was, iterating the variable instead of the modelling itself. I saved model_1 earlier, and iterate using model_1. I guess the coding could not pickup what is model_1 and thats why it plotted the graph separately. If you put your gist here, I would gladly star it.

    – Iqlaas Ismail
    Mar 31 at 1:33








2




2





are you aware that test_mean is not defined within the for loop?

– SamProell
Mar 28 at 7:16





are you aware that test_mean is not defined within the for loop?

– SamProell
Mar 28 at 7:16













@SamProell thanks for pointing. left it out on purpose. :)

– Iqlaas Ismail
Mar 28 at 9:34





@SamProell thanks for pointing. left it out on purpose. :)

– Iqlaas Ismail
Mar 28 at 9:34




2




2





i can't spot anything wrong with what you are doing.. This works for me: gist.github.com/SamProell/59d1d4fac1e319b3d19e98335058fc3f

– SamProell
Mar 28 at 10:01





i can't spot anything wrong with what you are doing.. This works for me: gist.github.com/SamProell/59d1d4fac1e319b3d19e98335058fc3f

– SamProell
Mar 28 at 10:01













@SamProell, thanks. My mistake was, iterating the variable instead of the modelling itself. I saved model_1 earlier, and iterate using model_1. I guess the coding could not pickup what is model_1 and thats why it plotted the graph separately. If you put your gist here, I would gladly star it.

– Iqlaas Ismail
Mar 31 at 1:33






@SamProell, thanks. My mistake was, iterating the variable instead of the modelling itself. I saved model_1 earlier, and iterate using model_1. I guess the coding could not pickup what is model_1 and thats why it plotted the graph separately. If you put your gist here, I would gladly star it.

– Iqlaas Ismail
Mar 31 at 1:33













1 Answer
1






active

oldest

votes


















1
















i can't spot anything wrong with what you are doing.. This works for me (taken in part from here):



import numpy as np
import matplotlib.pyplot as plt
from sklearn.naive_bayes import GaussianNB
from sklearn.svm import SVC
from sklearn.datasets import load_digits
from sklearn.model_selection import learning_curve

digits = load_digits()
X, y = digits.data, digits.target
for i in [GaussianNB(), SVC(gamma=0.001)]:
(train_sizes,
train_scores,
test_scores) = learning_curve(i, X, y, cv=5)
test_mean = np.mean(test_scores, axis=1)
plt.plot(train_sizes, test_mean, label="Cross-validation score")

plt.legend()
plt.show()





share|improve this answer
























    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );














    draft saved

    draft discarded
















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55391460%2fhow-to-plot-multiple-learning-curve-from-different-model-on-the-same-graph%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1
















    i can't spot anything wrong with what you are doing.. This works for me (taken in part from here):



    import numpy as np
    import matplotlib.pyplot as plt
    from sklearn.naive_bayes import GaussianNB
    from sklearn.svm import SVC
    from sklearn.datasets import load_digits
    from sklearn.model_selection import learning_curve

    digits = load_digits()
    X, y = digits.data, digits.target
    for i in [GaussianNB(), SVC(gamma=0.001)]:
    (train_sizes,
    train_scores,
    test_scores) = learning_curve(i, X, y, cv=5)
    test_mean = np.mean(test_scores, axis=1)
    plt.plot(train_sizes, test_mean, label="Cross-validation score")

    plt.legend()
    plt.show()





    share|improve this answer





























      1
















      i can't spot anything wrong with what you are doing.. This works for me (taken in part from here):



      import numpy as np
      import matplotlib.pyplot as plt
      from sklearn.naive_bayes import GaussianNB
      from sklearn.svm import SVC
      from sklearn.datasets import load_digits
      from sklearn.model_selection import learning_curve

      digits = load_digits()
      X, y = digits.data, digits.target
      for i in [GaussianNB(), SVC(gamma=0.001)]:
      (train_sizes,
      train_scores,
      test_scores) = learning_curve(i, X, y, cv=5)
      test_mean = np.mean(test_scores, axis=1)
      plt.plot(train_sizes, test_mean, label="Cross-validation score")

      plt.legend()
      plt.show()





      share|improve this answer



























        1














        1










        1









        i can't spot anything wrong with what you are doing.. This works for me (taken in part from here):



        import numpy as np
        import matplotlib.pyplot as plt
        from sklearn.naive_bayes import GaussianNB
        from sklearn.svm import SVC
        from sklearn.datasets import load_digits
        from sklearn.model_selection import learning_curve

        digits = load_digits()
        X, y = digits.data, digits.target
        for i in [GaussianNB(), SVC(gamma=0.001)]:
        (train_sizes,
        train_scores,
        test_scores) = learning_curve(i, X, y, cv=5)
        test_mean = np.mean(test_scores, axis=1)
        plt.plot(train_sizes, test_mean, label="Cross-validation score")

        plt.legend()
        plt.show()





        share|improve this answer













        i can't spot anything wrong with what you are doing.. This works for me (taken in part from here):



        import numpy as np
        import matplotlib.pyplot as plt
        from sklearn.naive_bayes import GaussianNB
        from sklearn.svm import SVC
        from sklearn.datasets import load_digits
        from sklearn.model_selection import learning_curve

        digits = load_digits()
        X, y = digits.data, digits.target
        for i in [GaussianNB(), SVC(gamma=0.001)]:
        (train_sizes,
        train_scores,
        test_scores) = learning_curve(i, X, y, cv=5)
        test_mean = np.mean(test_scores, axis=1)
        plt.plot(train_sizes, test_mean, label="Cross-validation score")

        plt.legend()
        plt.show()






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Apr 1 at 8:49









        SamProellSamProell

        3461 silver badge12 bronze badges




        3461 silver badge12 bronze badges





















            Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.







            Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.




















            draft saved

            draft discarded















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid …


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55391460%2fhow-to-plot-multiple-learning-curve-from-different-model-on-the-same-graph%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            How to preserve electronics (computers, tablets and phones) for hundreds of years Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) The network's official Twitter account is up and running again. What content…How might modern humans leave a message for 50,000 years?How would an aquatic race develop computers?How do we make computers care for human life?Keeping supplies for 1000 yearsWhat will cell phones become in 100 years?What body armor protects against a laser?Could a society attain 1800s technology if limited to using copper and bronze?Electricity power (magic) and electronicsScavenging metal resources in post-apocalypse after 100 yearsWhy would precursors create devices that can survive and still work after hundreds of years?

            155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해

            Convert JSON to MapSimplest way to convert a string representing JSON array into Java array List of key value pairsHow to take String JSON values into HashMapConvert a JSON String to a HashMapCreating BSON object from JSON stringJSONObject - How to get a value ?Better Map ConstructorReading JSON from Url javaUpdate columns if input values are not null otherwise ignore and keep the existing values of column in databaseHow to store object represented as Json string into Couchbase Lite?Go JSON into MapHow do I efficiently iterate over each entry in a Java Map?Sort a Map<Key, Value> by valuesHow to round a number to n decimal places in JavaCan comments be used in JSON?How do I read / convert an InputStream into a String in Java?How can I pretty-print JSON in a shell script?What is the correct JSON content type?How can I deserialize JSON to a simple Dictionary<string,string> in ASP.NET?Why does Google prepend while(1); to their JSON responses?Parse JSON in JavaScript?