目录
报错代码
model.predict(10)
报错结果:
ValueError: Expected 2D array, got scalar array instead: array=10. 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.
问题:
值错误,应为二维数组,得到的是一维数组。
如果数据具有单个特征,则使用array.reshape(-1, 1)对数据进行重塑。
解决方案:
import numpy as np
x = 10
x = np.array(x).reshape(-1, 1)
model.predict(x)
加入import numpy as np和array.reshape(-1, 1)则可以运行出结果