[英]ValueError: Unknown label type: continuous. When implementing regression
[英]Logistic regression: ValueError: Unknown label type: 'continuous'
我想使用逻辑回归来预测和绘制 Excel 数据集中的曲线<\/a>并获取其斜率系数。 但是,当我运行代码(见下文)时,会出现错误“ValueError: Unknown label type: 'continuous'.”。
我在类似的问题中读到 y 值应该是 'int' 类型,但我不想转换它,因为 y 数字介于 1.66 和 0.44 之间......
这种情况有解决方案还是我应该尝试另一个回归模型?
import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import PolynomialFeatures
import seaborn as sns
from sklearn.linear_model import LogisticRegression
df = pd.read_excel('Fatigue2.xlsx',sheet_name='Sheet4')
X = df[['Strain1', 'Temperature1']]
y = df['Cycles1']
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.25, random_state=101)
#poly = PolynomialFeatures(degree=2)
#X_ = poly.fit_transform(X_train)
LR = LogisticRegression()
LR.fit(X_train,y_train)
g = sns.lmplot(x='Cycles1', y='Strain1', hue = 'Temperature1', data=df, fit_reg= False)
g.set(xscale='log', yscale ='log')
g.set_axis_labels("Cycles (log N)", "Strain")
print ('Coefficients : ', LR.coef_, 'Intercept :', LR.intercept_)
来自sklearn
的LogisticRegression
是一个分类器,即它期望响应变量是分类的。
你的任务是回归。 此外,该图似乎没有右侧 logit 的渐近行为。 使用此处描述的多项式回归可能会获得更好的结果。
基于文档type_of_target(y)
:
确定目标指示的数据类型。
请注意,此类型是可以推断的最具体的类型。 例如:
binary
更具体但与multiclass
兼容。multiclass
of integers 更具体但与continuous
兼容。multilabel-indicator
更具体但与multiclass-multioutput
兼容。
参数
y
: 类数组
退货
目标类型:字符串
之一:
- 'continuous':
y
是一个类似于数组的浮点数,不全是整数,并且是 1d 或列向量。- ...
y
更改为y.astype(int)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.