简体   繁体   English

逻辑回归:ValueError:未知标签类型:“连续”

[英]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'.”。

I read in similar questions that the y values should be 'int' type but I don't want to convert it because the y numbers are between 1.66 and 0.44...我在类似的问题中读到 y 值应该是 'int' 类型,但我不想转换它,因为 y 数字介于 1.66 和 0.44 之间......

Is there a solution for this kind of cases or should I try another regression model?这种情况有解决方案还是我应该尝试另一个回归模型?

Thanks a lot in advance非常感谢提前

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.来自sklearnLogisticRegression是一个分类器,即它期望响应变量是分类的。

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 with multiclass . binary更具体但与multiclass兼容。
  • multiclass of integers is more specific but compatible with continuous . multiclass of integers 更具体但与continuous兼容。
  • multilabel-indicator is more specific but compatible with multiclass-multioutput . multilabel-indicator更具体但与multiclass-multioutput兼容。

Parameters参数

y : array-like y : 类数组

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 或列向量。
  • ... ...

change y as y.astype(int)y更改为y.astype(int)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 ValueError:未知标签类型:连续。 实施回归时 - ValueError: Unknown label type: continuous. When implementing regression ValueError: Unknown label type: &#39;continuous&#39; while using Logistical Regression - ValueError: Unknown label type: 'continuous' while using Logistical Regression ValueError:未知标签类型:&#39;连续 - ValueError: Unknown label type: 'continuous ValueError:未知标签类型:“连续” - ValueError: Unknown label type: 'continuous' ValueError:未知标签类型:SVM 中的“连续”错误 - ValueError: Unknown label type: 'continuous' Error in SVM sklearn - KNeighborsClassifier - ValueError: Unknown label type: &#39;continuous&#39; - sklearn - KNeighborsClassifier - ValueError: Unknown label type: 'continuous' ValueError:未知标签类型:“连续”,SVC Sklearn - ValueError: Unknown label type: 'continuous', SVC Sklearn 如何修复 ValueError:未知 label 类型:“连续”? - How to fix ValueError: Unknown label type: 'continuous'? ValueError:未知 label 类型:DecisionTreeClassifier() 中的“连续” - ValueError: Unknown label type: 'continuous' in DecisionTreeClassifier() Python ValueError:未知标签类型:&#39;continuous&#39; - Python ValueError: Unknown label type: 'continuous'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM