Skip to content

Commit b286b85

Browse files
committed
Add and print a total_n_estimators information
Add to bagging.Bagging._parallel_build_estimators a total_n_estimators parameter, to improve the (optional) information printed if verbose > 1. It felt weird to see 6 times in a row "building estimator 1 of 1" without any idea of total number of estimators to build, now it's fixed.
1 parent 7345351 commit b286b85

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

sklearn/ensemble/bagging.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434

3535

3636
def _parallel_build_estimators(n_estimators, ensemble, X, y, sample_weight,
37-
max_samples, seeds, verbose):
37+
max_samples, seeds, verbose, total_n_estimators):
3838
"""Private function used to build a batch of estimators within a job."""
3939
# Retrieve settings
4040
n_samples, n_features = X.shape
@@ -62,7 +62,8 @@ def _parallel_build_estimators(n_estimators, ensemble, X, y, sample_weight,
6262

6363
for i in range(n_estimators):
6464
if verbose > 1:
65-
print("building estimator %d of %d" % (i + 1, n_estimators))
65+
print("Building estimator %d of %d for this parallel run (total %d)..." %
66+
(i + 1, n_estimators, total_n_estimators))
6667

6768
random_state = check_random_state(seeds[i])
6869
seed = random_state.randint(MAX_INT)
@@ -343,6 +344,7 @@ def _fit(self, X, y, max_samples, max_depth=None, sample_weight=None):
343344
# Parallel loop
344345
n_jobs, n_estimators, starts = _partition_estimators(n_more_estimators,
345346
self.n_jobs)
347+
total_n_estimators = len(n_estimators)
346348

347349
# Advance random state to state after training
348350
# the first n_estimators
@@ -360,7 +362,8 @@ def _fit(self, X, y, max_samples, max_depth=None, sample_weight=None):
360362
sample_weight,
361363
max_samples,
362364
seeds[starts[i]:starts[i + 1]],
363-
verbose=self.verbose)
365+
verbose=self.verbose,
366+
total_n_estimators)
364367
for i in range(n_jobs))
365368

366369
# Reduce

0 commit comments

Comments
 (0)