sklearn中Logistic回归的值误差

时间:2019-06-12 09:44:36

标签: python

from sklearn.linear_model import LogisticRegression
lr = LogisticRegression()
lr.fit(mushroom_x, mushroom_y)
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)

<ipython-input-106-ec260714820e> in <module>
----> 1 lr.fit(mushroom_x, mushroom_y)

~/anaconda3/lib/python3.7/site-packages/sklearn/linear_model/logistic.py in fit(self, X, y, sample_weight)
   1286 
   1287         X, y = check_X_y(X, y, accept_sparse='csr', dtype=_dtype, order="C",
-> 1288                          accept_large_sparse=solver != 'liblinear')
   1289         check_classification_targets(y)
   1290         self.classes_ = np.unique(y)

~/anaconda3/lib/python3.7/site-packages/sklearn/utils/validation.py in check_X_y(X, y, accept_sparse, accept_large_sparse, dtype, order, copy, force_all_finite, ensure_2d, allow_nd, multi_output, ensure_min_samples, ensure_min_features, y_numeric, warn_on_dtype, estimator)
    759                         dtype=None)
    760     else:
--> 761         y = column_or_1d(y, warn=True)
    762         _assert_all_finite(y)
    763     if y_numeric and y.dtype.kind == 'O':

~/anaconda3/lib/python3.7/site-packages/sklearn/utils/validation.py in column_or_1d(y, warn)
    795         return np.ravel(y)
    796 
--> 797     raise ValueError("bad input shape {0}".format(shape))
    798 
    799 

ValueError: bad input shape (8124, 2)

我是这里机器学习的新手,我正试图找出一个.csv文件。

我仔细检查了有关输入错误的值错误的其他问题,但仍与此处的解决方案混淆。

1 个答案:

答案 0 :(得分:0)

Heresklearn.linear_model.LogisticRegression.fit的文档。您的标签y需要一个一维数组,其中元素数等于x中的样本数。就您而言,y是2D数组。不确定,但从外观上看,您可能已经交换了xy

相关问题