Last answered:

08 Apr 2020

Posted on:

07 Apr 2020

0

Value Error : Expected 2D array

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 answers ( 0 marked as helpful)
Instructor
Posted on:

08 Apr 2020

0
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

Submit an answer