[英]Logistic regression: ValueError: Unknown label type: 'continuous'
I want to use logistic regression to predict and plot a curve<\/a> from an Excel dataset and get its slope coefficients.我想使用逻辑回归来预测和绘制 Excel 数据集中的
曲线<\/a>并获取其斜率系数。 However, when I run the code (see below) the error " ValueError: Unknown label type: 'continuous'. " occurs.
但是,当我运行代码(见下文)时,会出现错误“ValueError: Unknown label type: 'continuous'.”。
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_)
LogisticRegression
from sklearn
is a classifier, ie it expects that the response variable is categorical.来自
sklearn
的LogisticRegression
是一个分类器,即它期望响应变量是分类的。
Your task is of regression.你的任务是回归。 Moreover, the plot does not seem to have the asymptotic behavior of a logit on the right.
此外,该图似乎没有右侧 logit 的渐近行为。 You may have better results using a polynomial regression as described here .
使用此处描述的多项式回归可能会获得更好的结果。
Based on docs type_of_target(y)
:基于文档
type_of_target(y)
:
Determine the type of data indicated by the target.
确定目标指示的数据类型。
Note that this type is the most specific type that can be inferred.
请注意,此类型是可以推断的最具体的类型。 For example:
例如:
binary
is more specific but compatible withmulticlass
.binary
更具体但与multiclass
兼容。multiclass
of integers is more specific but compatible withcontinuous
.multiclass
of integers 更具体但与continuous
兼容。multilabel-indicator
is more specific but compatible withmulticlass-multioutput
.multilabel-indicator
更具体但与multiclass-multioutput
兼容。
Parameters
参数
y
: array-likey
: 类数组
Returns
退货
target_type : string
目标类型:字符串
One of:
之一:
- 'continuous':
y
is an array-like of floats that are not all integers, and is 1d or a column vector.'continuous':
y
是一个类似于数组的浮点数,不全是整数,并且是 1d 或列向量。- ...
...
y
as y.astype(int)
y
更改为y.astype(int)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.