sklearn 错误集合

2019-04-29  本文已影响0人  sttech
ValueError: Expected 2D array, got 1D array instead:
错误图示
xPred = [102, 6]
yPred = regr.predict(xPred)

会出现以下错误

ValueError: Expected 2D array, got 1D array instead:
array=[102 6].
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.

解决方法

xPred = [100,6]
xPred = np.array(xPred).reshape(1,-1)
yPred = regr.predict(xPred)

原因是新版sklearn中所有的数据都应该是二维矩阵,需要使用.reshape(1,-1)进行转换。

上一篇 下一篇

猜你喜欢

热点阅读