Python sklearn错误:Expected 2D array, got scalar array instead…Reshape your data…
bmi_life_model.predict(21.079)
- 1
- 2
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.
按照回归模型预测,出现错误,该错误是由于sklearn版本更新后,数据维度不一致导致,代码改成以下即可:
bmi_life_model.predict([[21.079]])
- 1
array([[60.31486644]])
模型运行成功!
</div>
<link href="https://csdnimg.cn/release/phoenix/mdeditor/markdown_views-60ecaf1f42.css" rel="stylesheet">
</div>
</article>