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;
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
add a comment |
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
Try to make your data in proper order.
– lifeisshubh
Mar 26 at 23:40
What istrain
?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
add a comment |
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
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
python pandas numpy keras sklearn-pandas
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 istrain
?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
add a comment |
Try to make your data in proper order.
– lifeisshubh
Mar 26 at 23:40
What istrain
?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
add a comment |
2 Answers
2
active
oldest
votes
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))
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, movednew_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
add a comment |
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))
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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))
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, movednew_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
add a comment |
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))
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, movednew_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
add a comment |
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))
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))
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, movednew_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
add a comment |
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, movednew_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
add a comment |
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))
add a comment |
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))
add a comment |
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))
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))
answered Apr 9 at 0:43
grcgrc
419 bronze badges
419 bronze badges
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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