如何修复 ValueError:找到包含 0 个样本的数组

当我尝试训练模型时,我对尝试使用 sklearn 运行线性回归的 python 真的很陌生:

regressIt.fit(X_train, Y_train)

它抛出以下异常:

ValueError: Found array with 0 sample(s) (shape=(0, 546)) while a minimum of 1 is required.

我究竟做错了什么?

提前致谢。

stack overflow How to fix ValueError: Found array with 0 sample(s)
原文答案

答案:

作者头像

好的,我想我明白了
X=np.array(X).reshape((-1,1)) Should be this instead of ((1,-1)) Not sure why yet? Y=np.array(Y).reshape((-1,1)) #Also this print(str(regr.predict(X_test)))

作者头像
X_train, X_test, Y_train, Y_test = train_test_split(X, Y, test_size=0.3)
# don't keep the testing data 0 i gave 30% for example,
# for this add the next line in import
from sklearn.model_selection import train_test_split