Stacking (Stacked Generalization) ensemble implementations for classification and regression.
Classes
StackingClassifier for stacked generalization meta-learning.
__init__( self, classifiers: List[Any] = None, meta_classifier: Any = 'LogisticRegression', num_folds: int = 10, use_probabilities: bool = True, random_state: Optional[int] = None, )
Overview
The algorithm proceeds in two levels:
- Level-0 (Base classifiers):
- Level-1 (Meta-classifier):
- To predict new data, generate meta-features from level-0 classifiers
Theory
Given L base classifiers h_1, \ldots, h_L, the meta-features for sample x_i are constructed as:
When use_probabilities=True, each h_l(x_i) is a K-dimensional probability vector, yielding L \times K meta-features.
The meta-classifier g learns the combination function:
Cross-validation prevents overfitting by ensuring that meta-features for training sample x_i are generated by classifiers that did not see x_i during training.
Parameters
classifiers
meta_classifier
num_folds
use_probabilities
True) or one-hot encoded hard labels (False) as meta-features.
random_state
Attributes
base_estimators_
meta_estimator_
classes_
fit().
Notes
Complexity:
- Training: O(k \cdot \sum_{l=1}^{L} C_l + C_{\text{meta}}) where k = num_folds,
- Prediction: O(\sum_{l=1}^{L} C_l^{\text{pred}} + C_{\text{meta}}^{\text{pred}}) per sample
- When you have diverse base classifiers with complementary strengths
- When simple voting does not capture complex relationships between classifiers
- When you have enough data to support cross-validation without underfitting
- When you want the meta-learner to learn optimal combination weights automatically
References
See Also
Basic usage for stacked generalization:
>>> from tuiml.algorithms.ensemble import StackingClassifier
>>> import numpy as np
>>>
>>> # Create sample training data
>>> X_train = np.array([[1, 2], [2, 3], [3, 1], [4, 3], [5, 2]])
>>> y_train = np.array([0, 0, 1, 1, 1])
>>>
>>> # Fit the Stacking classifier
>>> clf = StackingClassifier(
... classifiers=['NaiveBayesClassifier', 'DecisionTreeClassifier'],
... meta_classifier='LogisticRegression'
... )
>>> clf.fit(X_train, y_train)
StackingClassifier(...)
>>> predictions = clf.predict(X_train)
Methods
get_parameter_schema
(cls) -> Dict[str, Dict[str, Any]]
get_capabilities
(cls) -> List[str]
get_complexity
(cls) -> str
get_references
(cls) -> List[str]
__repr__
(self) -> str
StackingRegressor for stacked generalization meta-learning regression.
__init__( self, regressors: List[Any] = None, meta_regressor: Any = 'GradientBoostingRegressor', num_folds: int = 10, random_state: Optional[int] = None, )
Overview
The algorithm proceeds in two levels:
- Level-0 (Base regressors):
- Level-1 (Meta-regressor):
- To predict new data, generate meta-features from level-0 regressors
Theory
Given L base regressors h_1, \ldots, h_L, the meta-features for sample x_i are constructed as:
The meta-regressor g learns the combination function:
Cross-validation prevents overfitting by ensuring that meta-features for training sample x_i are generated by regressors that did not see x_i during training.
Parameters
regressors
meta_regressor
num_folds
random_state
Attributes
base_estimators_
meta_estimator_
Notes
Complexity:
- Training: O(k \cdot \sum_{l=1}^{L} C_l + C_{\text{meta}}) where k = num_folds,
- Prediction: O(\sum_{l=1}^{L} C_l^{\text{pred}} + C_{\text{meta}}^{\text{pred}}) per sample
- When you have diverse base regressors with complementary strengths
- When simple averaging does not capture complex relationships between regressors
- When you have enough data to support cross-validation without underfitting
- When you want the meta-learner to learn optimal combination weights automatically
References
See Also
Basic usage for stacked generalization regression:
>>> from tuiml.algorithms.ensemble import StackingRegressor
>>> import numpy as np
>>>
>>> # Create sample training data
>>> X_train = np.array([[1, 2], [2, 3], [3, 1], [4, 3], [5, 2]])
>>> y_train = np.array([1.5, 2.3, 3.1, 4.2, 5.0])
>>>
>>> # Fit the Stacking regressor
>>> reg = StackingRegressor(
... regressors=['GradientBoostingRegressor'],
... meta_regressor='GradientBoostingRegressor'
... )
>>> reg.fit(X_train, y_train)
StackingRegressor(...)
>>> predictions = reg.predict(X_train)