fit()缺失1需要位置“y”

时间:2021-06-20 10:59:02

I am practicing a sklearn modeling on load_iris data. When I initiate LogisticRegression from sklearn.linear_model I receive an error when I try to fit the data.

我在load_iris数据上练习sklearn建模。当我从sklearn开始逻辑回归的时候。当我试图拟合数据时,我收到一个错误。

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!

任何帮助都将被感激!

1 个解决方案

#1


1  

You didn't instantiate LogisticRegression; you forgot the parentheses:

你没有实例化LogisticRegression;你忘记了括号:

logreg = LogisticRegression()

The error message arises because logreg.fit(X, y) can be thought of as syntactic sugar for 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; thus, the second argument does appear to be missing.

错误消息出现是因为logreg。拟合(X, y)可以被认为是logistic回归的语法糖。fit(logreg, X, y)。因为logreg在您的代码中只是对类的另一个引用,它将X解释为逻辑回归和y作为第一个参数的必要实例;因此,第二个参数似乎丢失了。

#1


1  

You didn't instantiate LogisticRegression; you forgot the parentheses:

你没有实例化LogisticRegression;你忘记了括号:

logreg = LogisticRegression()

The error message arises because logreg.fit(X, y) can be thought of as syntactic sugar for 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; thus, the second argument does appear to be missing.

错误消息出现是因为logreg。拟合(X, y)可以被认为是logistic回归的语法糖。fit(logreg, X, y)。因为logreg在您的代码中只是对类的另一个引用,它将X解释为逻辑回归和y作为第一个参数的必要实例;因此,第二个参数似乎丢失了。

相关文章