Skip to content

Commit 8ad2f5e

Browse files
committed
ENH: Make forest prediction code more robust to mutations of the estimators list
This can be useful to quickly study the impact of the size of the forest by subsampling from it for instance.
1 parent 2f998ca commit 8ad2f5e

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

sklearn/ensemble/forest.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,7 @@ def predict_proba(self, X):
472472
for j in xrange(1, len(all_proba)):
473473
proba += all_proba[j]
474474

475-
proba /= self.n_estimators
475+
proba /= len(self.estimators_)
476476

477477
else:
478478
for j in xrange(1, len(all_proba)):
@@ -572,7 +572,7 @@ def predict(self, X):
572572
for i in range(n_jobs))
573573

574574
# Reduce
575-
y_hat = sum(all_y_hat) / self.n_estimators
575+
y_hat = sum(all_y_hat) / len(self.estimators_)
576576

577577
return y_hat
578578

0 commit comments

Comments
 (0)