Python sklearn错误:Expected 2D array, got scalar array instead…Reshape your data…

bmi_life_model.fit(x,y)
bmi_life_model.predict(21.079)

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

According to the prediction of the regression model, an error occurred. The error was caused by the inconsistent data dimension after the sklearn version was updated. The code can be changed to the following:

bmi_life_model.predict([[21.079]])

array([[60.31486644]])

The model runs successfully!

Guess you like

Origin blog.csdn.net/weixin_45281949/article/details/102646599