sklearn警告:ConvergenceWarning: lbfgs failed to converge (status=1):

problem

This warning came out when training the logistic regression model.

model=LogisticRegression()
train_model("logistic regression",model,trainxv,trainy,testxv,testy)

The results are as follows:

ConvergenceWarning: lbfgs failed to converge (status=1):
STOP: TOTAL NO. of ITERATIONS REACHED LIMIT.

Insert picture description here

solve

The above runs by default:

LogisticRegression(... solver='lbfgs', max_iter=100 ...)

1.lbfgs problem

lbfgs stand for: “Limited-memory Broyden–Fletcher–Goldfarb–Shanno Algorithm”. It is one of the solvers’ algorithms provided by Scikit-Learn Library.

The term Limited-memory simply means it stores only a few vectors that represent the gradients approximation implicitly.

It has better convergence on relatively small datasets.

2. No convergence problems

This means that when training the model, the number of iterations of the parameters has reached the limit (default max_iter=100), but the changes in the parameters of the two iterations are still relatively large and still not below a small threshold, which is called no convergence.

However, this is just a warning (warm reminder), we either choose 1. Ignore, or 2. Increase the maximum number of iterations, or 3. Change other models or the parameter solver, or 4. Preprocess the data and extract More useful features.

We choose option 2, as follows:

model=LogisticRegression(max_iter=1000)
train_model("logistic regression",model,trainxv,trainy,testxv,testy)

We choose option 3, as follows:

model=LogisticRegression(solver="sag")
train_model("logistic regression",model,trainxv,trainy,testxv,testy)

We choose option 1, ignore all warnings, and absolutely. as follows:

import warnings
warnings.filterwarnings("ignore")

model=LogisticRegression()
train_model("logistic regression",model,trainxv,trainy,testxv,testy)

Guess you like

Origin blog.csdn.net/qq_43391414/article/details/113144702