Last answered:

15 Nov 2025

Posted on:

11 Nov 2021

28

The line reg.predict(1740) does not work anymore

The line reg.predict(1740) does not work anymore.
The new versions of sklearn requiere a matrix as input.
thus, it can be solved by using this code:

obs = 1740
obs_as_matrix = np.reshape(obs, (1,1))
reg.predict(obs_as_matrix)

Alternatively:

obs = 1740
obs_as_matrix = np.array([obs]).reshape(1, 1)
reg.predict(obs_as_matrix)

Or as a data frame:

obs = 1740
obs_as_matrix = pd.DataFrame({'SAT':[1740]})
reg.predict(obs_as_matrix)

5 answers ( 0 marked as helpful)
Posted on:

11 Nov 2021

1

Thank you for the clarification

Posted on:

13 Jun 2022

0

Thank you very much! I have had the same problem.

Posted on:

05 Nov 2022

0

You are great, keep up the good work.

Posted on:

07 Dec 2022

8

reg.predict([[1740]]) works as well

Posted on:

15 Nov 2025

0
Thanks for raising this issue! The explanation about newer scikit-learn versions requiring a 2D input for .predict() is really helpful. Using reg.predict([[1740]]) is a clear and simple fix. Great discussion! from brollyai

Submit an answer