Expected 2D array, got 1D arraySimple Digit Recognition OCR in OpenCV-PythonUnderstanding Keras LSTMsSKlearn reshape warning for X and YI am having the same dataset as other person and same code but I m getting error of expecting 2D arrayPrint predict ValueError: Expected 2D array, got 1D array insteadExpected 2D array, got 1D array instead errorExpected 2D array, got 1D array instead, any solution?Expected 2d array but got scalar array insteadHow to use Numpy reshape?ValueError on sklearn's linear_model.predict

Why should I use a big powerstone instead of smaller ones?

Should students have access to past exams or an exam bank?

Derivative is just speed of change?

Constant Scan spooling

Does the Oath of Redemption paladin's Emissary of Peace feature reflect damage taken as a result of the Aura of the Guardian feature?

PI 4 screen rotation from the terminal

Can birds evolve without trees?

How to trick a fairly simplistic kill-counter?

Can I say "Gesundheit" if someone is coughing?

How to derive trigonometric Cartesian equation from parametric

Can black block with a hanging piece in a back rank mate situation?

Why is “deal 6 damage” a legit phrase?

A game of red and black

How do people drown while wearing a life jacket?

How to gracefully excuse yourself from a meeting due to emergencies such as a restroom break?

What is the significance of $(logname)?

Return last number in sub-sequences in a list of integers

"Will flex for food". What does this phrase mean?

Word for giving preference to the oldest child

The grades of the students in a class

Has the US government provided details on plans to deal with AIDS and childhood cancer?

Basic transistor circuit

Can the additional attack from a Samurai fighter's Rapid Strike feature be made at advantage?

What's the term for a group of people who enjoy literary works?



Expected 2D array, got 1D array


Simple Digit Recognition OCR in OpenCV-PythonUnderstanding Keras LSTMsSKlearn reshape warning for X and YI am having the same dataset as other person and same code but I m getting error of expecting 2D arrayPrint predict ValueError: Expected 2D array, got 1D array insteadExpected 2D array, got 1D array instead errorExpected 2D array, got 1D array instead, any solution?Expected 2d array but got scalar array insteadHow to use Numpy reshape?ValueError on sklearn's linear_model.predict






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








0















I'm running the following code from github, but I'm getting an error. What's wrong?



https://github.com/susanli2016/Machine-Learning-with-Python/blob/master/Time%20Series%20ANN%20%26%20LSTM%20VIX.ipynb



Cell:



# scale train and test data to [-1, 1]
scaler = MinMaxScaler(feature_range=(-1, 1))
train_sc = scaler.fit_transform(train)
test_sc = scaler.transform(test)


Error:



ValueError: Expected 2D array, got 1D array instead:
array=[17.24 18.190001 19.219999 ... 10.47 10.18 11.04 ].
Reshape your data either using array.reshape(-1, 1) if your data has a single feature or array.reshape(1, -1) if it contains a single sample.









share|improve this question
























  • Try to make your data in proper order.

    – lifeisshubh
    Mar 26 at 23:40











  • What is train? pd.Series? np.array? If it's a series, just use .to_frame(). If it's np array, reshape it as suggested .reshape(-1,1)

    – rafaelc
    Mar 27 at 0:17

















0















I'm running the following code from github, but I'm getting an error. What's wrong?



https://github.com/susanli2016/Machine-Learning-with-Python/blob/master/Time%20Series%20ANN%20%26%20LSTM%20VIX.ipynb



Cell:



# scale train and test data to [-1, 1]
scaler = MinMaxScaler(feature_range=(-1, 1))
train_sc = scaler.fit_transform(train)
test_sc = scaler.transform(test)


Error:



ValueError: Expected 2D array, got 1D array instead:
array=[17.24 18.190001 19.219999 ... 10.47 10.18 11.04 ].
Reshape your data either using array.reshape(-1, 1) if your data has a single feature or array.reshape(1, -1) if it contains a single sample.









share|improve this question
























  • Try to make your data in proper order.

    – lifeisshubh
    Mar 26 at 23:40











  • What is train? pd.Series? np.array? If it's a series, just use .to_frame(). If it's np array, reshape it as suggested .reshape(-1,1)

    – rafaelc
    Mar 27 at 0:17













0












0








0








I'm running the following code from github, but I'm getting an error. What's wrong?



https://github.com/susanli2016/Machine-Learning-with-Python/blob/master/Time%20Series%20ANN%20%26%20LSTM%20VIX.ipynb



Cell:



# scale train and test data to [-1, 1]
scaler = MinMaxScaler(feature_range=(-1, 1))
train_sc = scaler.fit_transform(train)
test_sc = scaler.transform(test)


Error:



ValueError: Expected 2D array, got 1D array instead:
array=[17.24 18.190001 19.219999 ... 10.47 10.18 11.04 ].
Reshape your data either using array.reshape(-1, 1) if your data has a single feature or array.reshape(1, -1) if it contains a single sample.









share|improve this question














I'm running the following code from github, but I'm getting an error. What's wrong?



https://github.com/susanli2016/Machine-Learning-with-Python/blob/master/Time%20Series%20ANN%20%26%20LSTM%20VIX.ipynb



Cell:



# scale train and test data to [-1, 1]
scaler = MinMaxScaler(feature_range=(-1, 1))
train_sc = scaler.fit_transform(train)
test_sc = scaler.transform(test)


Error:



ValueError: Expected 2D array, got 1D array instead:
array=[17.24 18.190001 19.219999 ... 10.47 10.18 11.04 ].
Reshape your data either using array.reshape(-1, 1) if your data has a single feature or array.reshape(1, -1) if it contains a single sample.






python pandas numpy keras sklearn-pandas






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 26 at 23:33









grcgrc

419 bronze badges




419 bronze badges















  • Try to make your data in proper order.

    – lifeisshubh
    Mar 26 at 23:40











  • What is train? pd.Series? np.array? If it's a series, just use .to_frame(). If it's np array, reshape it as suggested .reshape(-1,1)

    – rafaelc
    Mar 27 at 0:17

















  • Try to make your data in proper order.

    – lifeisshubh
    Mar 26 at 23:40











  • What is train? pd.Series? np.array? If it's a series, just use .to_frame(). If it's np array, reshape it as suggested .reshape(-1,1)

    – rafaelc
    Mar 27 at 0:17
















Try to make your data in proper order.

– lifeisshubh
Mar 26 at 23:40





Try to make your data in proper order.

– lifeisshubh
Mar 26 at 23:40













What is train? pd.Series? np.array? If it's a series, just use .to_frame(). If it's np array, reshape it as suggested .reshape(-1,1)

– rafaelc
Mar 27 at 0:17





What is train? pd.Series? np.array? If it's a series, just use .to_frame(). If it's np array, reshape it as suggested .reshape(-1,1)

– rafaelc
Mar 27 at 0:17












2 Answers
2






active

oldest

votes


















2














The person who made that notebook was using a really old version of sklearn. In short, your features were of the form [row_1, row_2...row_n], when they should have been of the form [[row_1], [row_2]...[row_n]].



Accordingly, use this:



new_shape = (len(train), 1)

train_sc = scaler.fit_transform(np.reshape(train, new_shape))
test_sc = scaler.transform(np.reshape(test, new_shape))





share|improve this answer



























  • Thanks! But I got a new error: TypeError: len() takes exactly one argument (2 given)

    – grc
    Mar 26 at 23:57












  • @grc probably gmds meant (len(train), 1)

    – rafaelc
    Mar 27 at 0:15











  • @grc @RafaelC Yup, moved new_shape out into a separate statement and forgot to shift the brackets. Edited.

    – gmds
    Mar 27 at 1:12












  • Thanks. Now it returns this ERROR: Data must be 1-dimensional

    – grc
    Mar 29 at 22:19












  • If I write like this, it works, but the "test_sc" is not working. scaler = MinMaxScaler(feature_range=(-1, 1)) train = train.reshape(1,-1) train_sc = scaler.fit_transform(train)

    – grc
    Mar 29 at 22:36



















0














Solved the problem adding the methods below, which apparently transform train and test objects to numpy arrays. Is that correct?



scaler = MinMaxScaler(feature_range=(-1, 1))
train_sc = scaler.fit_transform(train.values.reshape(-1, 1))
test_sc = scaler.transform(test.values.reshape(-1,1))





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/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%2f55367676%2fexpected-2d-array-got-1d-array%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    2














    The person who made that notebook was using a really old version of sklearn. In short, your features were of the form [row_1, row_2...row_n], when they should have been of the form [[row_1], [row_2]...[row_n]].



    Accordingly, use this:



    new_shape = (len(train), 1)

    train_sc = scaler.fit_transform(np.reshape(train, new_shape))
    test_sc = scaler.transform(np.reshape(test, new_shape))





    share|improve this answer



























    • Thanks! But I got a new error: TypeError: len() takes exactly one argument (2 given)

      – grc
      Mar 26 at 23:57












    • @grc probably gmds meant (len(train), 1)

      – rafaelc
      Mar 27 at 0:15











    • @grc @RafaelC Yup, moved new_shape out into a separate statement and forgot to shift the brackets. Edited.

      – gmds
      Mar 27 at 1:12












    • Thanks. Now it returns this ERROR: Data must be 1-dimensional

      – grc
      Mar 29 at 22:19












    • If I write like this, it works, but the "test_sc" is not working. scaler = MinMaxScaler(feature_range=(-1, 1)) train = train.reshape(1,-1) train_sc = scaler.fit_transform(train)

      – grc
      Mar 29 at 22:36
















    2














    The person who made that notebook was using a really old version of sklearn. In short, your features were of the form [row_1, row_2...row_n], when they should have been of the form [[row_1], [row_2]...[row_n]].



    Accordingly, use this:



    new_shape = (len(train), 1)

    train_sc = scaler.fit_transform(np.reshape(train, new_shape))
    test_sc = scaler.transform(np.reshape(test, new_shape))





    share|improve this answer



























    • Thanks! But I got a new error: TypeError: len() takes exactly one argument (2 given)

      – grc
      Mar 26 at 23:57












    • @grc probably gmds meant (len(train), 1)

      – rafaelc
      Mar 27 at 0:15











    • @grc @RafaelC Yup, moved new_shape out into a separate statement and forgot to shift the brackets. Edited.

      – gmds
      Mar 27 at 1:12












    • Thanks. Now it returns this ERROR: Data must be 1-dimensional

      – grc
      Mar 29 at 22:19












    • If I write like this, it works, but the "test_sc" is not working. scaler = MinMaxScaler(feature_range=(-1, 1)) train = train.reshape(1,-1) train_sc = scaler.fit_transform(train)

      – grc
      Mar 29 at 22:36














    2












    2








    2







    The person who made that notebook was using a really old version of sklearn. In short, your features were of the form [row_1, row_2...row_n], when they should have been of the form [[row_1], [row_2]...[row_n]].



    Accordingly, use this:



    new_shape = (len(train), 1)

    train_sc = scaler.fit_transform(np.reshape(train, new_shape))
    test_sc = scaler.transform(np.reshape(test, new_shape))





    share|improve this answer















    The person who made that notebook was using a really old version of sklearn. In short, your features were of the form [row_1, row_2...row_n], when they should have been of the form [[row_1], [row_2]...[row_n]].



    Accordingly, use this:



    new_shape = (len(train), 1)

    train_sc = scaler.fit_transform(np.reshape(train, new_shape))
    test_sc = scaler.transform(np.reshape(test, new_shape))






    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Mar 27 at 1:11

























    answered Mar 26 at 23:37









    gmdsgmds

    13.9k3 gold badges11 silver badges38 bronze badges




    13.9k3 gold badges11 silver badges38 bronze badges















    • Thanks! But I got a new error: TypeError: len() takes exactly one argument (2 given)

      – grc
      Mar 26 at 23:57












    • @grc probably gmds meant (len(train), 1)

      – rafaelc
      Mar 27 at 0:15











    • @grc @RafaelC Yup, moved new_shape out into a separate statement and forgot to shift the brackets. Edited.

      – gmds
      Mar 27 at 1:12












    • Thanks. Now it returns this ERROR: Data must be 1-dimensional

      – grc
      Mar 29 at 22:19












    • If I write like this, it works, but the "test_sc" is not working. scaler = MinMaxScaler(feature_range=(-1, 1)) train = train.reshape(1,-1) train_sc = scaler.fit_transform(train)

      – grc
      Mar 29 at 22:36


















    • Thanks! But I got a new error: TypeError: len() takes exactly one argument (2 given)

      – grc
      Mar 26 at 23:57












    • @grc probably gmds meant (len(train), 1)

      – rafaelc
      Mar 27 at 0:15











    • @grc @RafaelC Yup, moved new_shape out into a separate statement and forgot to shift the brackets. Edited.

      – gmds
      Mar 27 at 1:12












    • Thanks. Now it returns this ERROR: Data must be 1-dimensional

      – grc
      Mar 29 at 22:19












    • If I write like this, it works, but the "test_sc" is not working. scaler = MinMaxScaler(feature_range=(-1, 1)) train = train.reshape(1,-1) train_sc = scaler.fit_transform(train)

      – grc
      Mar 29 at 22:36

















    Thanks! But I got a new error: TypeError: len() takes exactly one argument (2 given)

    – grc
    Mar 26 at 23:57






    Thanks! But I got a new error: TypeError: len() takes exactly one argument (2 given)

    – grc
    Mar 26 at 23:57














    @grc probably gmds meant (len(train), 1)

    – rafaelc
    Mar 27 at 0:15





    @grc probably gmds meant (len(train), 1)

    – rafaelc
    Mar 27 at 0:15













    @grc @RafaelC Yup, moved new_shape out into a separate statement and forgot to shift the brackets. Edited.

    – gmds
    Mar 27 at 1:12






    @grc @RafaelC Yup, moved new_shape out into a separate statement and forgot to shift the brackets. Edited.

    – gmds
    Mar 27 at 1:12














    Thanks. Now it returns this ERROR: Data must be 1-dimensional

    – grc
    Mar 29 at 22:19






    Thanks. Now it returns this ERROR: Data must be 1-dimensional

    – grc
    Mar 29 at 22:19














    If I write like this, it works, but the "test_sc" is not working. scaler = MinMaxScaler(feature_range=(-1, 1)) train = train.reshape(1,-1) train_sc = scaler.fit_transform(train)

    – grc
    Mar 29 at 22:36






    If I write like this, it works, but the "test_sc" is not working. scaler = MinMaxScaler(feature_range=(-1, 1)) train = train.reshape(1,-1) train_sc = scaler.fit_transform(train)

    – grc
    Mar 29 at 22:36














    0














    Solved the problem adding the methods below, which apparently transform train and test objects to numpy arrays. Is that correct?



    scaler = MinMaxScaler(feature_range=(-1, 1))
    train_sc = scaler.fit_transform(train.values.reshape(-1, 1))
    test_sc = scaler.transform(test.values.reshape(-1,1))





    share|improve this answer





























      0














      Solved the problem adding the methods below, which apparently transform train and test objects to numpy arrays. Is that correct?



      scaler = MinMaxScaler(feature_range=(-1, 1))
      train_sc = scaler.fit_transform(train.values.reshape(-1, 1))
      test_sc = scaler.transform(test.values.reshape(-1,1))





      share|improve this answer



























        0












        0








        0







        Solved the problem adding the methods below, which apparently transform train and test objects to numpy arrays. Is that correct?



        scaler = MinMaxScaler(feature_range=(-1, 1))
        train_sc = scaler.fit_transform(train.values.reshape(-1, 1))
        test_sc = scaler.transform(test.values.reshape(-1,1))





        share|improve this answer













        Solved the problem adding the methods below, which apparently transform train and test objects to numpy arrays. Is that correct?



        scaler = MinMaxScaler(feature_range=(-1, 1))
        train_sc = scaler.fit_transform(train.values.reshape(-1, 1))
        test_sc = scaler.transform(test.values.reshape(-1,1))






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Apr 9 at 0:43









        grcgrc

        419 bronze badges




        419 bronze badges






























            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%2f55367676%2fexpected-2d-array-got-1d-array%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

            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

            은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현