from sklearn.linear_model import LogisticRegression
from sklearn.model_selection import train_test_split
x_train,x_test,y_train,y_test=train_test_split(x,y,test_size=0.3,random_state=0)
log=LogisticRegression()
print (x_train.shape) --(5, 13)
print (x_test.shape) --(3, 13)
print(y_train.shape) --(5,)
print(y_test.shape) --(3,)
log.fit(x_train,y_train)
请参阅以下内容 我已经从youtube和互联网来源获取了该代码,并使用上述代码给出了以下错误。请帮帮我 错误:
ValueError Traceback (most recent call last)
<ipython-input-16-86c1075a1e93> in <module>
----> 1 log.fit(x_train,y_train)
/srv/conda/lib/python3.6/site-packages/sklearn/linear_model/logistic.py in fit(self, X, y, sample_weight)
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)
1291 n_samples, n_features = X.shape
/srv/conda/lib/python3.6/site-packages/sklearn/utils/multiclass.py in check_classification_targets(y)
169 if y_type not in ['binary', 'multiclass', 'multiclass-multioutput',
170 'multilabel-indicator', 'multilabel-sequences']:
--> 171 raise ValueError("Unknown label type: %r" % y_type)
172
173
ValueError: Unknown label type: 'continuous'
答案 0 :(得分:1)
逻辑回归是一种预测二进制类别的统计方法。因变量或目标变量必须为二进制。就您而言,您有“连续”目标。
逻辑回归类型:
二进制Logistic回归:目标变量只有两个可能的结果。
多项式Logistic回归:目标变量具有三个或多个名义类别
序数逻辑回归:目标变量具有三个或多个序数类别(示例:产品等级从1到5)