我正在训练一个数字数据集,以便使用逻辑回归多类分类对数字进行分类。通过使用以下代码
from sklearn.datasets import load_digits
%matplotlib inline
import matplotlib.pyplot as plt
digits = load_digits()
plt.gray()
for i in range(5):
plt.matshow(digits.images[i])
from sklearn.linear_model import LogisticRegression
model = LogisticRegression()
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(digits.data,digits.target, test_size=0.2)
model.fit(X_train, y_train) 当我执行cell时,我在jupyter notebook中这样做
model.fit(X_train, y_train)我得到的警告就像
C:\Users\Shubham Teke\anaconda3\envs\allenv\lib\site-packages\sklearn\linear_model\_logistic.py:764: ConvergenceWarning: lbfgs failed to converge (status=1):
STOP: TOTAL NO. of ITERATIONS REACHED LIMIT.
Increase the number of iterations (max_iter) or scale the data as shown in:
https://scikit-learn.org/stable/modules/preprocessing.html
Please also refer to the documentation for alternative solver options:
https://scikit-learn.org/stable/modules/linear_model.html#logistic-regression
extra_warning_msg=_LOGISTIC_SOLVER_CONVERGENCE_MSG)
LogisticRegression()那么这个警告是什么,如何解决这个问题呢?
发布于 2020-09-25 14:38:01
这是因为max_iter停止了模型训练。也就是说,模型的参数不收敛,但迭代成为max_iter。
解决方案很简单。增加你的max_iter。
例如,
model = LogisticRegression(max_iter = 100000) 发布于 2020-09-25 14:40:42
这是警告,不是错误。你需要增加最大迭代次数。
默认值为100。试试这个
LogisticRegression(max_iter=1000)或增加1000以上
https://stackoverflow.com/questions/64059008
复制相似问题