77
votes

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

3 Answers

74
votes

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
41
votes

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.

11
votes

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.