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

            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