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

            SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

            용인 삼성생명 블루밍스 목차 통계 역대 감독 선수단 응원단 경기장 같이 보기 외부 링크 둘러보기 메뉴samsungblueminx.comeh선수 명단용인 삼성생명 블루밍스용인 삼성생명 블루밍스ehsamsungblueminx.comeheheheh

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