Liblinear failed to converge, increase the number of iterations (tested)
ConvergenceWarning: Liblinear failed to converge, increase the number of iterations. comes from LinearSVC or LogisticRegression(solver='liblinear'). In our test, raising max_iter to 100000 did not help; switching to dual=False converged in 27 iterations. Tested on scikit-learn 1.9.1.
1. The warning
import warnings
warnings.simplefilter("always")
from sklearn.datasets import load_breast_cancer
from sklearn.svm import LinearSVC
X, y = load_breast_cancer(return_X_y=True)
clf = LinearSVC(dual=True).fit(X, y)
print("n_iter_:", clf.n_iter_, "max_iter:", clf.max_iter)
Output:
/usr/local/lib/python3.15/site-packages/sklearn/svm/_base.py:1295: ConvergenceWarning: Liblinear failed to converge, increase the number of iterations.
warnings.warn(
n_iter_: 1000 max_iter: 1000
LinearSVC (and LogisticRegression(solver="liblinear")) use the liblinear library. With dual=True on this data (569 samples, 30 unscaled features) it hits max_iter=1000 without converging: n_iter_ equals max_iter and scikit-learn emits ConvergenceWarning: Liblinear failed to converge, increase the number of iterations.
2. Raising max_iter or scaling did not fix it here
import warnings
warnings.simplefilter("always")
from sklearn.datasets import load_breast_cancer
from sklearn.pipeline import make_pipeline
from sklearn.preprocessing import StandardScaler
from sklearn.svm import LinearSVC
X, y = load_breast_cancer(return_X_y=True)
clf = make_pipeline(StandardScaler(), LinearSVC(dual=True)).fit(X, y)
print("scaled n_iter_:", clf[-1].n_iter_, "accuracy:", round(clf.score(X, y), 3))
for n in (10_000, 100_000):
raw = LinearSVC(dual=True, max_iter=n).fit(X, y)
print(f"unscaled max_iter={n}: n_iter_ =", raw.n_iter_)
Output:
/usr/local/lib/python3.15/site-packages/sklearn/svm/_base.py:1295: ConvergenceWarning: Liblinear failed to converge, increase the number of iterations.
warnings.warn(
/usr/local/lib/python3.15/site-packages/sklearn/svm/_base.py:1295: ConvergenceWarning: Liblinear failed to converge, increase the number of iterations.
warnings.warn(
/usr/local/lib/python3.15/site-packages/sklearn/svm/_base.py:1295: ConvergenceWarning: Liblinear failed to converge, increase the number of iterations.
warnings.warn(
scaled n_iter_: 1000 accuracy: 0.988
unscaled max_iter=10000: n_iter_ = 10000
unscaled max_iter=100000: n_iter_ = 100000
The warning text says to increase iterations, but here the dual solver used every iteration even at max_iter=100000, and scaling with StandardScaler did not make it converge within 1000 either (accuracy was still 0.988, so the model is usable, just not at the optimum).
3. Fix: solve the primal problem (dual=False)
from sklearn.datasets import load_breast_cancer
from sklearn.svm import LinearSVC
X, y = load_breast_cancer(return_X_y=True)
print(X.shape) # (n_samples, n_features)
clf = LinearSVC(dual=False).fit(X, y)
print("dual=False n_iter_:", clf.n_iter_)
Output:
(569, 30)
dual=False n_iter_: 27
When you have more samples than features, use dual=False: it converged in 27 iterations, no warning. In current scikit-learn the default is dual="auto", which picks the primal problem in this case, so the warning usually comes from code that sets dual=True explicitly (or from older scikit-learn versions where True was the default). If you have more features than samples, keep dual=True and scale the features.
4. Suppress it (when you accept the result)
import warnings
from sklearn.datasets import load_breast_cancer
from sklearn.exceptions import ConvergenceWarning
from sklearn.svm import LinearSVC
X, y = load_breast_cancer(return_X_y=True)
with warnings.catch_warnings():
warnings.simplefilter("ignore", category=ConvergenceWarning)
clf = LinearSVC(dual=True).fit(X, y)
print("no warning printed; n_iter_ is still", clf.n_iter_)
Output:
no warning printed; n_iter_ is still 1000
Ignore only ConvergenceWarning inside warnings.catch_warnings() so other warnings stay visible. Silencing does not change the fit: n_iter_ is still 1000.
Related: lbfgs failed to converge ยท suppress scikit-learn warnings.
Frequently asked questions
How do I fix 'Liblinear failed to converge'?
If n_samples > n_features, use LinearSVC(dual=False) (or the default dual='auto'). Otherwise scale features with StandardScaler and raise max_iter.
Does increasing max_iter fix the liblinear warning?
Not always. In our test the dual solver still hit the limit at max_iter=100000, while dual=False converged in 27 iterations.
How do I suppress the liblinear ConvergenceWarning?
from sklearn.exceptions import ConvergenceWarning, then warnings.simplefilter('ignore', category=ConvergenceWarning) inside warnings.catch_warnings().
Written with AI assistance. Measured on 2026-10-23 in Docker: python:3-slim (Python 3.15.1) with scikit-learn 1.9.1. Each block was run verbatim and the output pasted unedited. PlainTables is our extension; Python and scikit-learn are free.