scanpy icon indicating copy to clipboard operation
scanpy copied to clipboard

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

Open zhangnan0107 opened this issue 3 years ago • 1 comments

  • [x] I have checked that this issue has not already been reported.
  • [ ] I have confirmed this bug exists on the latest version of scanpy.
  • [ ] (optional) I have confirmed this bug exists on the master branch of scanpy.

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?

zhangnan0107 avatar Mar 30 '22 08:03 zhangnan0107

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

jerviedog avatar May 17 '22 10:05 jerviedog