StandardScaler with Pipelines and GridSearchCV












1














I've put standardScaler on the pipeline, and
the results of CV_mlpregressor.predict(x_test), are weird. I think i must have to bring the values back from the standardScaler, but still can't figure how.



pipe_MLPRegressor = Pipeline([('scaler',  StandardScaler()),
('MLPRegressor', MLPRegressor(random_state = 42))])


grid_params_MLPRegressor = [{
'MLPRegressor__solver': ['lbfgs'],
'MLPRegressor__max_iter': [100,200,300,500],
'MLPRegressor__activation' : ['relu','logistic','tanh'],
'MLPRegressor__hidden_layer_sizes':[(2,), (4,),(2,2),(4,4),(4,2),(10,10),(2,2,2)],
}]


CV_mlpregressor = GridSearchCV (estimator = pipe_MLPRegressor,
param_grid = grid_params_MLPRegressor,
cv = 5,return_train_score=True, verbose=0)

CV_mlpregressor.fit(x_train, y_train)

CV_mlpregressor.predict(x_test)


The Results:



array([ 2.67564153e+04,  1.90010572e+04,  9.62702942e+04,  3.98791931e+04,
1.48889808e+03, 7.08980726e+03, 3.86311279e+02, 7.05602301e+04,
4.06858486e+03, 4.29186303e+04, 3.86701735e+03, 6.30228075e+04,
6.78276925e+04, -5.91956287e+02, -7.37680434e+02, 3.07485001e+04,
4.81417953e+03, 5.18697686e+03, 1.61221952e+04, 1.33794944e+04,
-1.48375101e+03, 1.80891807e+04, 1.39740243e+04, 6.57156849e+04,
3.32962481e+04, 5.71332087e+05, 1.79130092e+03, 5.25642370e+04,
2.08111172e+04, 4.31060127e+04])


Thanks in advance.










share|improve this question





























    1














    I've put standardScaler on the pipeline, and
    the results of CV_mlpregressor.predict(x_test), are weird. I think i must have to bring the values back from the standardScaler, but still can't figure how.



    pipe_MLPRegressor = Pipeline([('scaler',  StandardScaler()),
    ('MLPRegressor', MLPRegressor(random_state = 42))])


    grid_params_MLPRegressor = [{
    'MLPRegressor__solver': ['lbfgs'],
    'MLPRegressor__max_iter': [100,200,300,500],
    'MLPRegressor__activation' : ['relu','logistic','tanh'],
    'MLPRegressor__hidden_layer_sizes':[(2,), (4,),(2,2),(4,4),(4,2),(10,10),(2,2,2)],
    }]


    CV_mlpregressor = GridSearchCV (estimator = pipe_MLPRegressor,
    param_grid = grid_params_MLPRegressor,
    cv = 5,return_train_score=True, verbose=0)

    CV_mlpregressor.fit(x_train, y_train)

    CV_mlpregressor.predict(x_test)


    The Results:



    array([ 2.67564153e+04,  1.90010572e+04,  9.62702942e+04,  3.98791931e+04,
    1.48889808e+03, 7.08980726e+03, 3.86311279e+02, 7.05602301e+04,
    4.06858486e+03, 4.29186303e+04, 3.86701735e+03, 6.30228075e+04,
    6.78276925e+04, -5.91956287e+02, -7.37680434e+02, 3.07485001e+04,
    4.81417953e+03, 5.18697686e+03, 1.61221952e+04, 1.33794944e+04,
    -1.48375101e+03, 1.80891807e+04, 1.39740243e+04, 6.57156849e+04,
    3.32962481e+04, 5.71332087e+05, 1.79130092e+03, 5.25642370e+04,
    2.08111172e+04, 4.31060127e+04])


    Thanks in advance.










    share|improve this question



























      1












      1








      1







      I've put standardScaler on the pipeline, and
      the results of CV_mlpregressor.predict(x_test), are weird. I think i must have to bring the values back from the standardScaler, but still can't figure how.



      pipe_MLPRegressor = Pipeline([('scaler',  StandardScaler()),
      ('MLPRegressor', MLPRegressor(random_state = 42))])


      grid_params_MLPRegressor = [{
      'MLPRegressor__solver': ['lbfgs'],
      'MLPRegressor__max_iter': [100,200,300,500],
      'MLPRegressor__activation' : ['relu','logistic','tanh'],
      'MLPRegressor__hidden_layer_sizes':[(2,), (4,),(2,2),(4,4),(4,2),(10,10),(2,2,2)],
      }]


      CV_mlpregressor = GridSearchCV (estimator = pipe_MLPRegressor,
      param_grid = grid_params_MLPRegressor,
      cv = 5,return_train_score=True, verbose=0)

      CV_mlpregressor.fit(x_train, y_train)

      CV_mlpregressor.predict(x_test)


      The Results:



      array([ 2.67564153e+04,  1.90010572e+04,  9.62702942e+04,  3.98791931e+04,
      1.48889808e+03, 7.08980726e+03, 3.86311279e+02, 7.05602301e+04,
      4.06858486e+03, 4.29186303e+04, 3.86701735e+03, 6.30228075e+04,
      6.78276925e+04, -5.91956287e+02, -7.37680434e+02, 3.07485001e+04,
      4.81417953e+03, 5.18697686e+03, 1.61221952e+04, 1.33794944e+04,
      -1.48375101e+03, 1.80891807e+04, 1.39740243e+04, 6.57156849e+04,
      3.32962481e+04, 5.71332087e+05, 1.79130092e+03, 5.25642370e+04,
      2.08111172e+04, 4.31060127e+04])


      Thanks in advance.










      share|improve this question















      I've put standardScaler on the pipeline, and
      the results of CV_mlpregressor.predict(x_test), are weird. I think i must have to bring the values back from the standardScaler, but still can't figure how.



      pipe_MLPRegressor = Pipeline([('scaler',  StandardScaler()),
      ('MLPRegressor', MLPRegressor(random_state = 42))])


      grid_params_MLPRegressor = [{
      'MLPRegressor__solver': ['lbfgs'],
      'MLPRegressor__max_iter': [100,200,300,500],
      'MLPRegressor__activation' : ['relu','logistic','tanh'],
      'MLPRegressor__hidden_layer_sizes':[(2,), (4,),(2,2),(4,4),(4,2),(10,10),(2,2,2)],
      }]


      CV_mlpregressor = GridSearchCV (estimator = pipe_MLPRegressor,
      param_grid = grid_params_MLPRegressor,
      cv = 5,return_train_score=True, verbose=0)

      CV_mlpregressor.fit(x_train, y_train)

      CV_mlpregressor.predict(x_test)


      The Results:



      array([ 2.67564153e+04,  1.90010572e+04,  9.62702942e+04,  3.98791931e+04,
      1.48889808e+03, 7.08980726e+03, 3.86311279e+02, 7.05602301e+04,
      4.06858486e+03, 4.29186303e+04, 3.86701735e+03, 6.30228075e+04,
      6.78276925e+04, -5.91956287e+02, -7.37680434e+02, 3.07485001e+04,
      4.81417953e+03, 5.18697686e+03, 1.61221952e+04, 1.33794944e+04,
      -1.48375101e+03, 1.80891807e+04, 1.39740243e+04, 6.57156849e+04,
      3.32962481e+04, 5.71332087e+05, 1.79130092e+03, 5.25642370e+04,
      2.08111172e+04, 4.31060127e+04])


      Thanks in advance.







      python scikit-learn regression analysis






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 11 at 19:16

























      asked Nov 11 at 19:03









      Lain Iwakura

      254




      254
























          1 Answer
          1






          active

          oldest

          votes


















          1














          @Lian, I think you are doing everything in the correct way. Please check your data. I did an experiment with sklearn dataset and this works as expected.



          from sklearn.preprocessing import StandardScaler
          from sklearn.neural_network import MLPRegressor
          from sklearn.pipeline import Pipeline
          from sklearn.model_selection import GridSearchCV
          from sklearn.datasets import load_boston
          from sklearn.model_selection import train_test_split
          import numpy as np

          x,y = load_boston(return_X_y=True)


          xtrain, xtest, ytrain, ytest = train_test_split(x,y, random_state=6784)

          pipe_MLPRegressor = Pipeline([('scaler', StandardScaler()),
          ('MLPRegressor', MLPRegressor(random_state = 42))])
          grid_params_MLPRegressor = [{
          'MLPRegressor__solver': ['lbfgs'],
          'MLPRegressor__max_iter': [100,200,300,500],
          'MLPRegressor__activation' : ['relu','logistic','tanh'],
          'MLPRegressor__hidden_layer_sizes':[(2,), (4,),(2,2),(4,4),(4,2),(10,10),(2,
          2,2)],}]


          CV_mlpregressor = GridSearchCV (estimator = pipe_MLPRegressor,
          param_grid = grid_params_MLPRegressor,
          cv = 5,return_train_score=True, verbose=0)

          CV_mlpregressor.fit(xtrain, ytrain)

          ypred=CV_mlpregressor.predict(xtest)

          print np.c_[ytest, ypred]


          This prints



          array([[ 29.9       ,  30.79749986],
          [ 22.5 , 24.52180656],
          [ 22.6 , 18.9567779 ],
          [ 28.7 , 22.17189123],
          [ 13.8 , 19.16797811],
          [ 21.2 , 24.63527335],
          [ 11.3 , 13.58962076],
          [ 23. , 18.33693455],
          [ 12.7 , 15.52294714],
          [ 23.3 , 26.65083451],
          [ 25.3 , 24.04219813],
          [ 22.6 , 19.81454969],
          [ 36.2 , 22.16994764],
          [ 17.9 , 11.1221789 ],
          [ 18.5 , 17.84162452],
          [ 16.8 , 22.99832673],
          [ 20.3 , 20.22598426],
          [ 23.9 , 26.80997945],
          [ 17.6 , 16.08188321],
          [ 23.2 , 18.5995955 ],
          [ 48.3 , 43.37911488],
          [ 19.1 , 22.36379857],





          share|improve this answer





















          • Thanks for your reply, I'll check my database!
            – Lain Iwakura
            Nov 12 at 23:16











          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%2f53252156%2fstandardscaler-with-pipelines-and-gridsearchcv%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














          @Lian, I think you are doing everything in the correct way. Please check your data. I did an experiment with sklearn dataset and this works as expected.



          from sklearn.preprocessing import StandardScaler
          from sklearn.neural_network import MLPRegressor
          from sklearn.pipeline import Pipeline
          from sklearn.model_selection import GridSearchCV
          from sklearn.datasets import load_boston
          from sklearn.model_selection import train_test_split
          import numpy as np

          x,y = load_boston(return_X_y=True)


          xtrain, xtest, ytrain, ytest = train_test_split(x,y, random_state=6784)

          pipe_MLPRegressor = Pipeline([('scaler', StandardScaler()),
          ('MLPRegressor', MLPRegressor(random_state = 42))])
          grid_params_MLPRegressor = [{
          'MLPRegressor__solver': ['lbfgs'],
          'MLPRegressor__max_iter': [100,200,300,500],
          'MLPRegressor__activation' : ['relu','logistic','tanh'],
          'MLPRegressor__hidden_layer_sizes':[(2,), (4,),(2,2),(4,4),(4,2),(10,10),(2,
          2,2)],}]


          CV_mlpregressor = GridSearchCV (estimator = pipe_MLPRegressor,
          param_grid = grid_params_MLPRegressor,
          cv = 5,return_train_score=True, verbose=0)

          CV_mlpregressor.fit(xtrain, ytrain)

          ypred=CV_mlpregressor.predict(xtest)

          print np.c_[ytest, ypred]


          This prints



          array([[ 29.9       ,  30.79749986],
          [ 22.5 , 24.52180656],
          [ 22.6 , 18.9567779 ],
          [ 28.7 , 22.17189123],
          [ 13.8 , 19.16797811],
          [ 21.2 , 24.63527335],
          [ 11.3 , 13.58962076],
          [ 23. , 18.33693455],
          [ 12.7 , 15.52294714],
          [ 23.3 , 26.65083451],
          [ 25.3 , 24.04219813],
          [ 22.6 , 19.81454969],
          [ 36.2 , 22.16994764],
          [ 17.9 , 11.1221789 ],
          [ 18.5 , 17.84162452],
          [ 16.8 , 22.99832673],
          [ 20.3 , 20.22598426],
          [ 23.9 , 26.80997945],
          [ 17.6 , 16.08188321],
          [ 23.2 , 18.5995955 ],
          [ 48.3 , 43.37911488],
          [ 19.1 , 22.36379857],





          share|improve this answer





















          • Thanks for your reply, I'll check my database!
            – Lain Iwakura
            Nov 12 at 23:16
















          1














          @Lian, I think you are doing everything in the correct way. Please check your data. I did an experiment with sklearn dataset and this works as expected.



          from sklearn.preprocessing import StandardScaler
          from sklearn.neural_network import MLPRegressor
          from sklearn.pipeline import Pipeline
          from sklearn.model_selection import GridSearchCV
          from sklearn.datasets import load_boston
          from sklearn.model_selection import train_test_split
          import numpy as np

          x,y = load_boston(return_X_y=True)


          xtrain, xtest, ytrain, ytest = train_test_split(x,y, random_state=6784)

          pipe_MLPRegressor = Pipeline([('scaler', StandardScaler()),
          ('MLPRegressor', MLPRegressor(random_state = 42))])
          grid_params_MLPRegressor = [{
          'MLPRegressor__solver': ['lbfgs'],
          'MLPRegressor__max_iter': [100,200,300,500],
          'MLPRegressor__activation' : ['relu','logistic','tanh'],
          'MLPRegressor__hidden_layer_sizes':[(2,), (4,),(2,2),(4,4),(4,2),(10,10),(2,
          2,2)],}]


          CV_mlpregressor = GridSearchCV (estimator = pipe_MLPRegressor,
          param_grid = grid_params_MLPRegressor,
          cv = 5,return_train_score=True, verbose=0)

          CV_mlpregressor.fit(xtrain, ytrain)

          ypred=CV_mlpregressor.predict(xtest)

          print np.c_[ytest, ypred]


          This prints



          array([[ 29.9       ,  30.79749986],
          [ 22.5 , 24.52180656],
          [ 22.6 , 18.9567779 ],
          [ 28.7 , 22.17189123],
          [ 13.8 , 19.16797811],
          [ 21.2 , 24.63527335],
          [ 11.3 , 13.58962076],
          [ 23. , 18.33693455],
          [ 12.7 , 15.52294714],
          [ 23.3 , 26.65083451],
          [ 25.3 , 24.04219813],
          [ 22.6 , 19.81454969],
          [ 36.2 , 22.16994764],
          [ 17.9 , 11.1221789 ],
          [ 18.5 , 17.84162452],
          [ 16.8 , 22.99832673],
          [ 20.3 , 20.22598426],
          [ 23.9 , 26.80997945],
          [ 17.6 , 16.08188321],
          [ 23.2 , 18.5995955 ],
          [ 48.3 , 43.37911488],
          [ 19.1 , 22.36379857],





          share|improve this answer





















          • Thanks for your reply, I'll check my database!
            – Lain Iwakura
            Nov 12 at 23:16














          1












          1








          1






          @Lian, I think you are doing everything in the correct way. Please check your data. I did an experiment with sklearn dataset and this works as expected.



          from sklearn.preprocessing import StandardScaler
          from sklearn.neural_network import MLPRegressor
          from sklearn.pipeline import Pipeline
          from sklearn.model_selection import GridSearchCV
          from sklearn.datasets import load_boston
          from sklearn.model_selection import train_test_split
          import numpy as np

          x,y = load_boston(return_X_y=True)


          xtrain, xtest, ytrain, ytest = train_test_split(x,y, random_state=6784)

          pipe_MLPRegressor = Pipeline([('scaler', StandardScaler()),
          ('MLPRegressor', MLPRegressor(random_state = 42))])
          grid_params_MLPRegressor = [{
          'MLPRegressor__solver': ['lbfgs'],
          'MLPRegressor__max_iter': [100,200,300,500],
          'MLPRegressor__activation' : ['relu','logistic','tanh'],
          'MLPRegressor__hidden_layer_sizes':[(2,), (4,),(2,2),(4,4),(4,2),(10,10),(2,
          2,2)],}]


          CV_mlpregressor = GridSearchCV (estimator = pipe_MLPRegressor,
          param_grid = grid_params_MLPRegressor,
          cv = 5,return_train_score=True, verbose=0)

          CV_mlpregressor.fit(xtrain, ytrain)

          ypred=CV_mlpregressor.predict(xtest)

          print np.c_[ytest, ypred]


          This prints



          array([[ 29.9       ,  30.79749986],
          [ 22.5 , 24.52180656],
          [ 22.6 , 18.9567779 ],
          [ 28.7 , 22.17189123],
          [ 13.8 , 19.16797811],
          [ 21.2 , 24.63527335],
          [ 11.3 , 13.58962076],
          [ 23. , 18.33693455],
          [ 12.7 , 15.52294714],
          [ 23.3 , 26.65083451],
          [ 25.3 , 24.04219813],
          [ 22.6 , 19.81454969],
          [ 36.2 , 22.16994764],
          [ 17.9 , 11.1221789 ],
          [ 18.5 , 17.84162452],
          [ 16.8 , 22.99832673],
          [ 20.3 , 20.22598426],
          [ 23.9 , 26.80997945],
          [ 17.6 , 16.08188321],
          [ 23.2 , 18.5995955 ],
          [ 48.3 , 43.37911488],
          [ 19.1 , 22.36379857],





          share|improve this answer












          @Lian, I think you are doing everything in the correct way. Please check your data. I did an experiment with sklearn dataset and this works as expected.



          from sklearn.preprocessing import StandardScaler
          from sklearn.neural_network import MLPRegressor
          from sklearn.pipeline import Pipeline
          from sklearn.model_selection import GridSearchCV
          from sklearn.datasets import load_boston
          from sklearn.model_selection import train_test_split
          import numpy as np

          x,y = load_boston(return_X_y=True)


          xtrain, xtest, ytrain, ytest = train_test_split(x,y, random_state=6784)

          pipe_MLPRegressor = Pipeline([('scaler', StandardScaler()),
          ('MLPRegressor', MLPRegressor(random_state = 42))])
          grid_params_MLPRegressor = [{
          'MLPRegressor__solver': ['lbfgs'],
          'MLPRegressor__max_iter': [100,200,300,500],
          'MLPRegressor__activation' : ['relu','logistic','tanh'],
          'MLPRegressor__hidden_layer_sizes':[(2,), (4,),(2,2),(4,4),(4,2),(10,10),(2,
          2,2)],}]


          CV_mlpregressor = GridSearchCV (estimator = pipe_MLPRegressor,
          param_grid = grid_params_MLPRegressor,
          cv = 5,return_train_score=True, verbose=0)

          CV_mlpregressor.fit(xtrain, ytrain)

          ypred=CV_mlpregressor.predict(xtest)

          print np.c_[ytest, ypred]


          This prints



          array([[ 29.9       ,  30.79749986],
          [ 22.5 , 24.52180656],
          [ 22.6 , 18.9567779 ],
          [ 28.7 , 22.17189123],
          [ 13.8 , 19.16797811],
          [ 21.2 , 24.63527335],
          [ 11.3 , 13.58962076],
          [ 23. , 18.33693455],
          [ 12.7 , 15.52294714],
          [ 23.3 , 26.65083451],
          [ 25.3 , 24.04219813],
          [ 22.6 , 19.81454969],
          [ 36.2 , 22.16994764],
          [ 17.9 , 11.1221789 ],
          [ 18.5 , 17.84162452],
          [ 16.8 , 22.99832673],
          [ 20.3 , 20.22598426],
          [ 23.9 , 26.80997945],
          [ 17.6 , 16.08188321],
          [ 23.2 , 18.5995955 ],
          [ 48.3 , 43.37911488],
          [ 19.1 , 22.36379857],






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 12 at 14:09









          sukhbinder

          31223




          31223












          • Thanks for your reply, I'll check my database!
            – Lain Iwakura
            Nov 12 at 23:16


















          • Thanks for your reply, I'll check my database!
            – Lain Iwakura
            Nov 12 at 23:16
















          Thanks for your reply, I'll check my database!
          – Lain Iwakura
          Nov 12 at 23:16




          Thanks for your reply, I'll check my database!
          – Lain Iwakura
          Nov 12 at 23:16


















          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.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • 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%2f53252156%2fstandardscaler-with-pipelines-and-gridsearchcv%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

          Full-time equivalent

          さくらももこ

          13 indicted, 8 arrested in Calif. drug cartel investigation