Expected 2D array, got 1D array instead: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.
错误代码:
model.fit(x_train,y_train)
新版sklearn中,所有数据都应为二维矩阵,独行独列也应是二维。
正确代码:
model.fit(x_train.reshqp(-1,1),y_train)
在新版 sklearn 中,所有输入数据必须为二维。遇到`Expected2Darray,got1Darray instead`错误时,需使用`reshape`方法调整数据形状。正确做法是将一维数据重塑为(-1, 1)或(1, -1)。修正后的代码为`model.fit(x_train.reshape(-1,1), y_train)`。
1万+

被折叠的 条评论
为什么被折叠?



