简体   繁体   English

fit()缺少1个必需的位置'y'

[英]fit() Missing 1 Required Positional 'y'

I am practicing a sklearn modeling on load_iris data. 我正在练习对load_iris数据进行sklearn建模。 When I initiate LogisticRegression from sklearn.linear_model I receive an error when I try to fit the data. 当我从sklearn.linear_model启动LogisticRegression时,当我尝试拟合数据时收到错误。

Below you may check my code: 您可以在下面查看我的代码:

      from sklearn.datasets import load_iris
      from sklearn.linear_model import LogisticRegression 

      logreg = LogisticRegression
      iris = load_iris()

      X = iris.data
      y = iris.target

      logreg.fit(X,y)

The code above prints out the following error: 上面的代码打印出以下错误:

fit() missing 1 required positional argument y fit()缺少1个必要的位置参数y

Any help would be appreciated! 任何帮助,将不胜感激!

You didn't instantiate LogisticRegression ; 你没有实例化LogisticRegression ; you forgot the parentheses: 你忘记了括号:

logreg = LogisticRegression()

The error message arises because logreg.fit(X, y) can be thought of as syntactic sugar for LogisticRegression.fit(logreg, X, y) . 出现错误消息是因为logreg.fit(X, y)可以被认为是LogisticRegression.fit(logreg, X, y)语法糖。 Since logreg in your code is just another reference to the class, it is interpreting X as the required instance of LogisticRegression and y as the first argument; 由于代码中的logreg只是对类的另一个引用,因此它将X解释为LogisticRegression的必需实例,将y为第一个参数; thus, the second argument does appear to be missing. 因此,第二个论点确实似乎缺失了。

暂无
暂无

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

相关问题 fit() 缺少 1 个必需的位置参数:'y' - fit() missing 1 required positional argument: 'y' TypeError: fit() 缺少 1 个必需的位置参数:'y' while GridSearching CNN - TypeError: fit() missing 1 required positional argument: 'y' while GridSearching CNN 实现逻辑回归“TypeError: fit() missing 1 required positional argument: 'y'” - Implementing Logistic Regression “TypeError: fit() missing 1 required positional argument: 'y'” 逻辑回归类型错误:fit() 缺少 1 个必需的位置参数:'y' - Logistic Regression TypeError: fit() missing 1 required positional argument: 'y' 类型错误:fit() 缺少 1 个必需的位置参数:'y'(使用 sklearn - ExtraTreesRegressor) - TypeError: fit() missing 1 required positional argument: 'y' (using sklearn - ExtraTreesRegressor) 简单线性回归错误 - fit() 缺少 1 个必需的位置参数:'y' - Simple Linear Regression Error - fit() missing 1 required positional argument: 'y' TypeError:fit()缺少1个必需的位置参数:'y' - TypeError: fit() missing 1 required positional argument: 'y' please 如何消除此错误?fit() 缺少 1 个必需的位置参数:'y' - How to remove this error?fit() missing 1 required positional argument: 'y' scikit-learn-TypeError:fit()缺少1个必需的位置参数:“ y” - scikit-learn - TypeError: fit() missing 1 required positional argument: 'y' 逻辑回归:fit() 缺少 1 个必需的位置参数:'y' - Logistic Regression: fit() missing 1 required positional argument: 'y'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM