@@ -39,6 +39,11 @@ class _BaseVoting(TransformerMixin, _BaseHeterogeneousEnsemble):
3939 instead.
4040 """
4141
42+ def _log_message (self , name , idx , total ):
43+ if not self .verbose :
44+ return None
45+ return '(%d of %d) Processing %s' % (idx , total , name )
46+
4247 @property
4348 def _weights_not_none (self ):
4449 """Get the weights of not `None` estimators."""
@@ -63,9 +68,14 @@ def fit(self, X, y, sample_weight=None):
6368 % (len (self .weights ), len (self .estimators )))
6469
6570 self .estimators_ = Parallel (n_jobs = self .n_jobs )(
66- delayed (_parallel_fit_estimator )(clone (clf ), X , y ,
67- sample_weight = sample_weight )
68- for clf in clfs if clf not in (None , 'drop' )
71+ delayed (_parallel_fit_estimator )(
72+ clone (clf ), X , y ,
73+ sample_weight = sample_weight ,
74+ message_clsname = 'Voting' ,
75+ message = self ._log_message (names [idx ],
76+ idx + 1 , len (clfs ))
77+ )
78+ for idx , clf in enumerate (clfs ) if clf not in (None , 'drop' )
6979 )
7080
7181 self .named_estimators_ = Bunch ()
@@ -122,6 +132,10 @@ class VotingClassifier(ClassifierMixin, _BaseVoting):
122132 flatten_transform=False, it returns
123133 (n_classifiers, n_samples, n_classes).
124134
135+ verbose : bool, default=False
136+ If True, the time elapsed while fitting will be printed as it
137+ is completed.
138+
125139 Attributes
126140 ----------
127141 estimators_ : list of classifiers
@@ -176,13 +190,14 @@ class VotingClassifier(ClassifierMixin, _BaseVoting):
176190 (6, 6)
177191 """
178192
179- def __init__ (self , estimators , voting = 'hard' , weights = None , n_jobs = None ,
180- flatten_transform = True ):
193+ def __init__ (self , estimators , voting = 'hard' , weights = None ,
194+ n_jobs = None , flatten_transform = True , verbose = False ):
181195 super ().__init__ (estimators = estimators )
182196 self .voting = voting
183197 self .weights = weights
184198 self .n_jobs = n_jobs
185199 self .flatten_transform = flatten_transform
200+ self .verbose = verbose
186201
187202 def fit (self , X , y , sample_weight = None ):
188203 """Fit the estimators.
@@ -346,6 +361,10 @@ class VotingRegressor(RegressorMixin, _BaseVoting):
346361 ``-1`` means using all processors. See :term:`Glossary <n_jobs>`
347362 for more details.
348363
364+ verbose : bool, default=False
365+ If True, the time elapsed while fitting will be printed as it
366+ is completed.
367+
349368 Attributes
350369 ----------
351370 estimators_ : list of regressors
@@ -376,10 +395,11 @@ class VotingRegressor(RegressorMixin, _BaseVoting):
376395 [ 3.3 5.7 11.8 19.7 28. 40.3]
377396 """
378397
379- def __init__ (self , estimators , weights = None , n_jobs = None ):
398+ def __init__ (self , estimators , weights = None , n_jobs = None , verbose = False ):
380399 super ().__init__ (estimators = estimators )
381400 self .weights = weights
382401 self .n_jobs = n_jobs
402+ self .verbose = verbose
383403
384404 def fit (self , X , y , sample_weight = None ):
385405 """Fit the estimators.
0 commit comments