how should i choose random_state to got precise consequenceHow should I read a file line-by-line in Python?TPOTClassifier producing errorsShould I specify a random_state in any classifier when doing a 10x10 StratifiedShuffleSplit?Scikit learn (Python 3.5): Do I need to import a library to make this work?Create model using one - hot encoding in KerasClassification with one file with entirely the training and another file with entirely testWhat should be the precise coordinates in basemap() for Europe?How to choose randomly in PythonWhich credentials should I choose and how?Training SVM with word2vector data

Can you move on your turn, and then use the Ready Action to move again on another creature's turn?

The deliberate use of misleading terminology

Why is there a need to modify system call tables in linux?

If Sweden was to magically float away, at what altitude would it be visible from the southern hemisphere?

Is it possible to change original filename of an exe?

Is having a hidden directory under /etc safe?

Why does the UK have more political parties than the US?

What is/are this/these giant NASA box(es)?

Could IPv6 make NAT / port numbers redundant?

Where can I find the list of all tendons in the human body?

Why would Lupin kill Pettigrew?

Strange math syntax in old basic listing

What is game ban VS VAC ban in steam?

Is there an evolutionary advantage to having two heads?

How can I include a header file that contains `>` in its name?

Can a non-EU citizen travel within the Schengen area without identity documents?

How can I prevent interns from being expendable?

Get LaTeX form from step by step solution

Do you play the upbeat when beginning to play a series of notes, and then after?

Looking after a wayward brother in mother's will

How did early x86 BIOS programmers manage to program full blown TUIs given very few bytes of ROM/EPROM?

Improve OR inside INNER JOIN

Is the world in Game of Thrones spherical or flat?

Is this light switch installation safe and legal?



how should i choose random_state to got precise consequence


How should I read a file line-by-line in Python?TPOTClassifier producing errorsShould I specify a random_state in any classifier when doing a 10x10 StratifiedShuffleSplit?Scikit learn (Python 3.5): Do I need to import a library to make this work?Create model using one - hot encoding in KerasClassification with one file with entirely the training and another file with entirely testWhat should be the precise coordinates in basemap() for Europe?How to choose randomly in PythonWhich credentials should I choose and how?Training SVM with word2vector data






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















When I use random_state=10. y_test[1] worked, but y_test[2 or 3 or...] did not.
So I tried to use other random_state, like 42 or 20, but upon changing, random_state.y_test[10] did not work too.



I'm not sure if the problem comes from y_test or from random_state.
And i wanna try to figure out why changing the value of random_state changes the precision of r2_score as well.



Thanks a lot



x = df[['mileage','engine_power','feature_1','feature_2','feature_3','feature_4','feature_5','feature_6','feature_7','feature_8','car_type']]
y = df['price']

x_train,x_test,y_train,y_test = train_test_split(x,y,test_size=0.2,random_state=10)

lr =LinearRegression()
lr.fit(x_train,y_train)
predict_lr = lr.predict(x_test)

print('real value y_test[1]:'+str(y_test[1])+' predict:'+str(lr.predict(x_test.iloc[[1],:])))
print('real value y_test[2]:'+str(y_test[2])+' predict:'+str(lr.predict(x_test.iloc[[2],:])))
print('scort:',lr.score(x_test,y_test))
print('r2 score:',r2_score(y_test,predict_lr))

>>>real value y_test[1]:69700 predict:[12659.21124934]
---------------------------------------------------------------------------
KeyError Traceback (most recent call last)
<ipython-input-48-e556e02e9019> in <module>
3 predict_lr = lr.predict(x_test)
4 print('real value y_test[1]:'+str(y_test[1])+' predict:'+str(lr.predict(x_test.iloc[[1],:])))
----> 5 print('real value y_test[2]:'+str(y_test[5])+' predict:'+str(lr.predict(x_test.iloc[[2],:])))
6
7 print('scort:',lr.score(x_test,y_test))
KeyError: 5









share|improve this question






























    0















    When I use random_state=10. y_test[1] worked, but y_test[2 or 3 or...] did not.
    So I tried to use other random_state, like 42 or 20, but upon changing, random_state.y_test[10] did not work too.



    I'm not sure if the problem comes from y_test or from random_state.
    And i wanna try to figure out why changing the value of random_state changes the precision of r2_score as well.



    Thanks a lot



    x = df[['mileage','engine_power','feature_1','feature_2','feature_3','feature_4','feature_5','feature_6','feature_7','feature_8','car_type']]
    y = df['price']

    x_train,x_test,y_train,y_test = train_test_split(x,y,test_size=0.2,random_state=10)

    lr =LinearRegression()
    lr.fit(x_train,y_train)
    predict_lr = lr.predict(x_test)

    print('real value y_test[1]:'+str(y_test[1])+' predict:'+str(lr.predict(x_test.iloc[[1],:])))
    print('real value y_test[2]:'+str(y_test[2])+' predict:'+str(lr.predict(x_test.iloc[[2],:])))
    print('scort:',lr.score(x_test,y_test))
    print('r2 score:',r2_score(y_test,predict_lr))

    >>>real value y_test[1]:69700 predict:[12659.21124934]
    ---------------------------------------------------------------------------
    KeyError Traceback (most recent call last)
    <ipython-input-48-e556e02e9019> in <module>
    3 predict_lr = lr.predict(x_test)
    4 print('real value y_test[1]:'+str(y_test[1])+' predict:'+str(lr.predict(x_test.iloc[[1],:])))
    ----> 5 print('real value y_test[2]:'+str(y_test[5])+' predict:'+str(lr.predict(x_test.iloc[[2],:])))
    6
    7 print('scort:',lr.score(x_test,y_test))
    KeyError: 5









    share|improve this question


























      0












      0








      0








      When I use random_state=10. y_test[1] worked, but y_test[2 or 3 or...] did not.
      So I tried to use other random_state, like 42 or 20, but upon changing, random_state.y_test[10] did not work too.



      I'm not sure if the problem comes from y_test or from random_state.
      And i wanna try to figure out why changing the value of random_state changes the precision of r2_score as well.



      Thanks a lot



      x = df[['mileage','engine_power','feature_1','feature_2','feature_3','feature_4','feature_5','feature_6','feature_7','feature_8','car_type']]
      y = df['price']

      x_train,x_test,y_train,y_test = train_test_split(x,y,test_size=0.2,random_state=10)

      lr =LinearRegression()
      lr.fit(x_train,y_train)
      predict_lr = lr.predict(x_test)

      print('real value y_test[1]:'+str(y_test[1])+' predict:'+str(lr.predict(x_test.iloc[[1],:])))
      print('real value y_test[2]:'+str(y_test[2])+' predict:'+str(lr.predict(x_test.iloc[[2],:])))
      print('scort:',lr.score(x_test,y_test))
      print('r2 score:',r2_score(y_test,predict_lr))

      >>>real value y_test[1]:69700 predict:[12659.21124934]
      ---------------------------------------------------------------------------
      KeyError Traceback (most recent call last)
      <ipython-input-48-e556e02e9019> in <module>
      3 predict_lr = lr.predict(x_test)
      4 print('real value y_test[1]:'+str(y_test[1])+' predict:'+str(lr.predict(x_test.iloc[[1],:])))
      ----> 5 print('real value y_test[2]:'+str(y_test[5])+' predict:'+str(lr.predict(x_test.iloc[[2],:])))
      6
      7 print('scort:',lr.score(x_test,y_test))
      KeyError: 5









      share|improve this question
















      When I use random_state=10. y_test[1] worked, but y_test[2 or 3 or...] did not.
      So I tried to use other random_state, like 42 or 20, but upon changing, random_state.y_test[10] did not work too.



      I'm not sure if the problem comes from y_test or from random_state.
      And i wanna try to figure out why changing the value of random_state changes the precision of r2_score as well.



      Thanks a lot



      x = df[['mileage','engine_power','feature_1','feature_2','feature_3','feature_4','feature_5','feature_6','feature_7','feature_8','car_type']]
      y = df['price']

      x_train,x_test,y_train,y_test = train_test_split(x,y,test_size=0.2,random_state=10)

      lr =LinearRegression()
      lr.fit(x_train,y_train)
      predict_lr = lr.predict(x_test)

      print('real value y_test[1]:'+str(y_test[1])+' predict:'+str(lr.predict(x_test.iloc[[1],:])))
      print('real value y_test[2]:'+str(y_test[2])+' predict:'+str(lr.predict(x_test.iloc[[2],:])))
      print('scort:',lr.score(x_test,y_test))
      print('r2 score:',r2_score(y_test,predict_lr))

      >>>real value y_test[1]:69700 predict:[12659.21124934]
      ---------------------------------------------------------------------------
      KeyError Traceback (most recent call last)
      <ipython-input-48-e556e02e9019> in <module>
      3 predict_lr = lr.predict(x_test)
      4 print('real value y_test[1]:'+str(y_test[1])+' predict:'+str(lr.predict(x_test.iloc[[1],:])))
      ----> 5 print('real value y_test[2]:'+str(y_test[5])+' predict:'+str(lr.predict(x_test.iloc[[2],:])))
      6
      7 print('scort:',lr.score(x_test,y_test))
      KeyError: 5






      python-3.x random-seed






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 29 at 4:44









      kerwei

      1,5191920




      1,5191920










      asked Mar 24 at 10:04









      韋辰姜韋辰姜

      12




      12






















          0






          active

          oldest

          votes












          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/3.0/"u003ecc by-sa 3.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%2f55322633%2fhow-should-i-choose-random-state-to-got-precise-consequence%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes















          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%2f55322633%2fhow-should-i-choose-random-state-to-got-precise-consequence%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

          Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

          Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

          Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript