The 365 Data Science team is proud to invite you to our own community forum. A very well built system to support your queries, questions and give the chance to show your knowledge and help others in their path of becoming Data Science specialists.
Ask
Anybody can ask a question
Answer
Anybody can answer
Vote
The best answers are voted up and moderated by our team

Value Error : Expected 2D array

Value Error : Expected 2D array

0
Votes
1
Answer

In ‘Simple Linear Regression with sklearn – Summary Table’ Lecture

After following the whole lecture and reshaping x to x_matrix, everything was running smoothly until I have to run  the ‘reg.predict(1740)’ command.

It gives me the same error.

ValueError: Expected 2D array, got scalar array instead: array=1740. 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.

1 Answer

365 Team
0
Votes

Hi Tanbir,
Thank you for reaching out.
Depending on your version of sklearn this may or may not be an issue. To turn the number to a 2D array, please add double square brackets like below:

reg.predict([[1740]])

Best,
Iliya