Implementation:Scikit learn Scikit learn BaseEnsemble
| Knowledge Sources | |
|---|---|
| Domains | Machine Learning, Ensemble Methods |
| Last Updated | 2026-02-08 15:00 GMT |
Overview
Concrete base class for ensemble-based estimators provided by scikit-learn.
Description
The ensemble/_base module provides the foundational infrastructure for ensemble methods. It includes _fit_single_estimator for fitting individual estimators within ensemble jobs, _set_random_states for deterministic random state management across sub-estimators, and the base class for building ensemble estimators that aggregate multiple base estimator predictions.
Usage
Use these utilities when implementing custom ensemble methods that need to fit multiple base estimators in parallel, manage random states for reproducibility, or build on the ensemble base class hierarchy.
Code Reference
Source Location
- Repository: scikit-learn
- File: sklearn/ensemble/_base.py
Signature
def _fit_single_estimator(
estimator, X, y, fit_params, message_clsname=None, message=None
):
...
def _set_random_states(estimator, random_state=None):
...
class BaseEnsemble(MetaEstimatorMixin, BaseEstimator, metaclass=ABCMeta):
@abstractmethod
def __init__(self, estimator=None, *, n_estimators=10):
...
def _validate_estimator(self):
...
Import
from sklearn.ensemble._base import BaseEnsemble, _fit_single_estimator
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| estimator | estimator instance | Yes | Base estimator to fit within the ensemble |
| X | array-like of shape (n_samples, n_features) | Yes | Training input samples |
| y | array-like of shape (n_samples,) | Yes | Target values |
| fit_params | dict | No | Additional parameters passed to the estimator's fit method |
| n_estimators | int | No | Number of base estimators in the ensemble |
Outputs
| Name | Type | Description |
|---|---|---|
| estimator | fitted estimator | The fitted base estimator |
| estimators_ | list | List of fitted sub-estimators |
Usage Examples
Basic Usage
from sklearn.ensemble import BaggingClassifier
from sklearn.tree import DecisionTreeClassifier
from sklearn.datasets import make_classification
X, y = make_classification(random_state=42)
# BaggingClassifier inherits from BaseEnsemble
clf = BaggingClassifier(
estimator=DecisionTreeClassifier(),
n_estimators=10,
random_state=42
)
clf.fit(X, y)
print(len(clf.estimators_)) # 10