逻辑回归错误对象没有属性'_validate_data'

问题描述 投票:0回答:2

我正在训练一个逻辑分类器,在调用分类器之后,我似乎无法拟合训练数据。这就是我得到的。

# calling the classifier 
from sklearn.linear_model import LogisticRegression

# instantiated the classifier
log model = LogisticRegression()

# when I try to fit the model with
logmodel.fit(X_train,y_train)

我收到此错误

------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-143-0b508b2e1562> in <module>
----> 1 logmodel.fit(X_train,y_train)

/opt/anaconda3/lib/python3.7/site-packages/sklearn/linear_model/_logistic.py in fit(self, X, y, sample_weight)
   1340             _dtype = [np.float64, np.float32]
   1341 
-> 1342         X, y = self._validate_data(X, y, accept_sparse='csr', dtype=_dtype,
   1343                                    order="C",
   1344                                    accept_large_sparse=solver != 'liblinear')

AttributeError: 'LogisticRegression' object has no attribute '_validate_data'

有人可以帮忙吗?

python classification
2个回答
0
投票

改变:

from sklearn.linear_model import LogisticRegression

import sklearn.linear_model as lm

并使用

实例化分类器
log_model = lm.LogisticRegression()

应该可以解决问题。


0
投票

我希望您不要使用 log model 而不是 logmodel 来实例化 LogisticRegression 方法。

© www.soinside.com 2019 - 2024. All rights reserved.