python - 逻辑回归拟合时显示值错误
问题描述
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'
解决方案
逻辑回归是一种用于预测二元类的统计方法。因变量或目标变量必须是二元的。在您的情况下,您有“连续”目标。
逻辑回归的类型:
二元逻辑回归:目标变量只有两种可能的结果。
多项 Logistic 回归:目标变量具有三个或更多名义类别
序数逻辑回归:目标变量具有三个或更多序数类别(示例:产品评分从 1 到 5)
推荐阅读
- python - 如果键值相同,则在 python 对象中添加列表
- flutter - TextOverFlow 颤振
- git - 疑难解答:如何让 Git 在提交时使用 VS Code?
- python - 用于排除特定文本的正则表达式
- npm - 有没有办法在 webpack 浏览器扩展应用程序中打开文件
- android - Android Room.databaseBuilder().createFromFile() 静默失败
- java - 在 intellij 中生成 WSDL 时出错:ClassNotFoundException: org.apache.woden.WSDLException
- sql - 在存储过程中使用嵌套的 case、when 和 else 条件
- python - 如何检查命令 cv2.line 是否更改了 python opencv 中的图像
- scala - 无法重写递归调用:它不在尾部位置