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