scverse / scanpy

Single-cell analysis in Python. Scales to >1M cells.
https://scanpy.readthedocs.io
BSD 3-Clause "New" or "Revised" License
1.89k stars 594 forks source link

"ConvergenceWarning" in sklearn when calling ”sc.tl.rank_genes_groups“ with method='logreg' #2195

Open zhangnan0107 opened 2 years ago

zhangnan0107 commented 2 years ago

Note: Please read this guide detailing how to provide the necessary information for us to reproduce your bug.

Minimal code sample (that we can copy&paste without having any data)

sc.tl.rank_genes_groups(adata, 'leiden', method='logreg')
~/miniconda3/envs/tangram-env/lib/python3.8/site-packages/sklearn/linear_model/_logistic.py:814: 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
  n_iter_i = _check_optimize_result(
    finished (0:07:47)

Versions

scikit-learn=1.0.2 scanpy=1.8.2

It seems the result was still not converged when using the maximal iteration parameter (max_iter=100) in LogisticRegression function of sklearn. I'd like to ask are there any possibilities to pass any parameters from scanpy to sklearn to increase the max_iter value?
jerviedog commented 2 years ago

sc.tl.rank_genes_groups(adata, 'leiden', method='logreg',max_iter=1000) worked.