Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions python/cuml/cuml/ensemble/randomforest_common.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,10 @@ class BaseRandomForestModel(UniversalBase):
self.treelite_serialized_model = None
self._cpu_model_class_lock = threading.RLock()

def __len__(self):
"""Return the number of estimators in the ensemble."""
return self.n_estimators

def _get_max_feat_val(self) -> float:
if isinstance(self.max_features, int):
return self.max_features/self.n_cols
Expand Down
7 changes: 7 additions & 0 deletions python/cuml/cuml/tests/test_random_forest.py
Original file line number Diff line number Diff line change
Expand Up @@ -1447,3 +1447,10 @@ def test_rf_predict_returns_int():
clf = cuml.ensemble.RandomForestClassifier().fit(X, y)
pred = clf.predict(X)
assert pred.dtype == np.int64


def test_ensemble_estimator_length():
X, y = make_classification()
clf = cuml.ensemble.RandomForestClassifier(n_estimators=3)
clf.fit(X, y)
assert len(clf) == 3