108

Is there any way to have a progress bar to the fit method in scikit-learn ?

Is it possible to include a custom one with something like Pyprind ?

3 Answers3

105

If you initialize the model with verbose=1 before calling fit you should get some kind of output indicating the progress.

For example sklearn.ensemble.GradientBoostingClassifer(verbose=1) provides progress output that looks like this:

  Iter       Train Loss   Remaining Time
     1           1.2811            0.71s
     2           1.2595            0.58s
     3           1.2402            0.50s
     4           1.2263            0.46s
     5           1.2121            0.43s
     6           1.1999            0.41s
     7           1.1876            0.39s
     8           1.1761            0.38s
     9           1.1673            0.37s
    10           1.1591            0.36s
    20           1.1021            0.29s
    30           1.0511            0.27s
    40           1.0116            0.25s
    50           0.9830            0.22s
    60           0.9581            0.19s
    70           0.9377            0.16s
    80           0.9169            0.14s
    90           0.9049            0.12s
   100           0.8973            0.10s
maxymoo
  • 35,286
  • 11
  • 92
  • 119
  • 12
    fit() got an unexpected keyword argument 'verbose' – Martin Thoma Jun 09 '16 at 07:13
  • 11
    Add the keyword to the model, not the fit method call. Also, using SVR, setting verbose=True added no output as far as I can tell. – Ondrej Skopek Sep 08 '16 at 09:45
  • 4
    Unless I'm missing something, the meta-estimators used for multiclass/multilabel don't allow such keywords. For example you can't use verbose=True as a parameter to OneVsRestClassifier(), only to the classifier you're using within it. This is unfortunate because you can't get a sense of high-level progress. – Stephen Aug 14 '17 at 02:53
  • how does it know the remaining time? – Lei Yang May 25 '23 at 03:36
50

Many models support a verbose argument which gives progress (and sometimes an indication on the rate of convergence).

e.g.

clf = MLPClassifier(verbose=True)

(see MLPClassifier )

If you have a loop outside of the learning model, I recommend tqdm.

Sheshank S.
  • 3,053
  • 3
  • 19
  • 39
seveibar
  • 4,403
  • 4
  • 30
  • 31
22

Not all scikit-learn models support the verbose parameter

Unfortunately not all scikit-learn models allow the verbose parameter. Off the top of my head I can say these models do not allow verbose parameter (there may be more):

Yet curiously ExtraTreesClassifier which also belongs to sklearn.ensemble (just like AdaBoostClassifier), does allow it.

Looks like not all members of sklearn.ensemble share the same base properties.

  • [PCA](https://scikit-learn.org/stable/modules/generated/sklearn.decomposition.PCA.html) also. – huang Jun 19 '21 at 14:21