【发布时间】:2014-09-17 22:22:59
【问题描述】:
我是机器学习的新手,我正在尝试使用 scikit-learn 在 Python 中设置逻辑回归以进行预测。我已经设置了一个小型模拟数据集,但是在扩展此代码以适用于更大的数据集时,我遇到了有关 ValueError 的问题。这是我的代码:
inputData = np.genfromtxt(file, skip_header=1, unpack=True)
print "X array shape: ",inputData.shape
inputAnswers = np.genfromtxt(file2, skip_header=1, unpack=True)
print "Y array shape: ",inputAnswers.shape
logreg = LogisticRegression(penalty='l2',C=2.0)
logreg.fit(inputData, inputAnswers)
inputData 二维数组(矩阵)有 149 行和 231 列。我正在尝试将其拟合到具有 149 行的 inputAnswers 数组,正确对应于 inputData 数组的 149 行。但是,这是我收到的输出:
X array shape: (231, 149)
Y array shape: (149,)
Traceback (most recent call last):
File "LogRegTry_rawData.py", line 26, in <module>
logreg.fit(inputData, inputAnswers)
File "[path]", line 676, in fit
(X.shape[0], y.shape[0]))
ValueError: X and y have incompatible shapes.
X has 231 samples, but y has 149.
我了解错误的含义,但我不确定为什么会出现这种情况以及如何解决它。任何帮助是极大的赞赏。谢谢!
【问题讨论】:
标签: python arrays scikit-learn prediction logistic-regression