Ensemble¶
- class endgame.ensemble.VotingClassifier(estimators, voting='soft', weights=None, flatten_transform=True, n_jobs=None, verbose=False)[source]¶
Bases:
BaseEstimator,ClassifierMixinSoft / hard voting meta-classifier.
- Parameters:
estimators (list of (str, estimator) tuples) – Named base classifiers.
voting ({'hard', 'soft'}, default='soft') –
'hard': majority-vote on predicted labels.'soft': average predicted probabilities, then argmax.
weights (array-like of shape (n_estimators,), optional) – Per-estimator weights.
Nonemeans uniform.flatten_transform (bool, default=True) – If
True,transformreturns shape(n_samples, n_classifiers * n_classes)instead of 3-D.n_jobs (int or None, default=None) – Parallel fitting jobs.
-1uses all CPUs.verbose (bool, default=False) – Print progress during fit.
Examples
>>> vc = VotingClassifier( ... estimators=[("rf", RandomForest()), ("lr", LogisticRegression())], ... voting="soft", ... ) >>> vc.fit(X_train, y_train).predict(X_test)
- fit(X, y, sample_weight=None, **fit_params)[source]¶
Fit all base estimators.
- Parameters:
X (array-like of shape (n_samples, n_features))
y (array-like of shape (n_samples,))
sample_weight (array-like, optional)
- predict(X)[source]¶
Predict class labels.
- Parameters:
X (array-like of shape (n_samples, n_features))
- Returns:
ndarray of shape (n_samples,)
- predict_proba(X)[source]¶
Average predicted probabilities.
- Parameters:
X (array-like of shape (n_samples, n_features))
- Returns:
ndarray of shape (n_samples, n_classes)
- transform(X)[source]¶
Return per-estimator predictions or probabilities.
- Parameters:
X (array-like of shape (n_samples, n_features))
- Returns:
ndarray
- get_params(deep=True)[source]¶
Get parameters for this estimator.
- Parameters:
deep (bool, default=True) – If True, will return the parameters for this estimator and contained subobjects that are estimators.
- Returns:
params (dict) – Parameter names mapped to their values.
- property named_estimators: dict[str, BaseEstimator]¶
Access fitted estimators by name.
- set_fit_request(*, sample_weight='$UNCHANGED$')¶
Configure whether metadata should be requested to be passed to the
fitmethod.Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with
enable_metadata_routing=True(seesklearn.set_config()). Please check the User Guide on how the routing mechanism works.The options for each parameter are:
True: metadata is requested, and passed tofitif provided. The request is ignored if metadata is not provided.False: metadata is not requested and the meta-estimator will not pass it tofit.None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.Added in version 1.3.
- Parameters:
sample_weight (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
sample_weightparameter infit.self (VotingClassifier)
- Returns:
self (object) – The updated object.
- Return type:
- set_score_request(*, sample_weight='$UNCHANGED$')¶
Configure whether metadata should be requested to be passed to the
scoremethod.Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with
enable_metadata_routing=True(seesklearn.set_config()). Please check the User Guide on how the routing mechanism works.The options for each parameter are:
True: metadata is requested, and passed toscoreif provided. The request is ignored if metadata is not provided.False: metadata is not requested and the meta-estimator will not pass it toscore.None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.Added in version 1.3.
- Parameters:
sample_weight (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
sample_weightparameter inscore.self (VotingClassifier)
- Returns:
self (object) – The updated object.
- Return type:
- class endgame.ensemble.VotingRegressor(estimators, weights=None, n_jobs=None, verbose=False)[source]¶
Bases:
BaseEstimator,RegressorMixinVoting meta-regressor: averages predictions from multiple regressors.
- Parameters:
Examples
>>> vr = VotingRegressor( ... estimators=[("ridge", Ridge()), ("rf", RandomForestRegressor())], ... weights=[1, 2], ... ) >>> vr.fit(X_train, y_train).predict(X_test)
- property named_estimators: dict[str, BaseEstimator]¶
- set_fit_request(*, sample_weight='$UNCHANGED$')¶
Configure whether metadata should be requested to be passed to the
fitmethod.Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with
enable_metadata_routing=True(seesklearn.set_config()). Please check the User Guide on how the routing mechanism works.The options for each parameter are:
True: metadata is requested, and passed tofitif provided. The request is ignored if metadata is not provided.False: metadata is not requested and the meta-estimator will not pass it tofit.None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.Added in version 1.3.
- Parameters:
sample_weight (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
sample_weightparameter infit.self (VotingRegressor)
- Returns:
self (object) – The updated object.
- Return type:
- set_score_request(*, sample_weight='$UNCHANGED$')¶
Configure whether metadata should be requested to be passed to the
scoremethod.Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with
enable_metadata_routing=True(seesklearn.set_config()). Please check the User Guide on how the routing mechanism works.The options for each parameter are:
True: metadata is requested, and passed toscoreif provided. The request is ignored if metadata is not provided.False: metadata is not requested and the meta-estimator will not pass it toscore.None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.Added in version 1.3.
- Parameters:
sample_weight (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
sample_weightparameter inscore.self (VotingRegressor)
- Returns:
self (object) – The updated object.
- Return type:
- class endgame.ensemble.BaggingClassifier(base_estimator=None, n_estimators=10, max_samples=1.0, max_features=1.0, bootstrap=True, bootstrap_features=False, oob_score=False, n_jobs=None, random_state=None, verbose=False)[source]¶
Bases:
BaseEstimator,ClassifierMixinBootstrap Aggregating classifier.
- Parameters:
base_estimator (estimator, optional) – Base learner to bag. Default:
DecisionTreeClassifier().n_estimators (int, default=10) – Number of bootstrap replicas.
max_samples (float or int, default=1.0) – Fraction (if float) or count (if int) of samples per bag.
max_features (float or int, default=1.0) – Fraction (if float) or count (if int) of features per bag.
bootstrap (bool, default=True) – Sample rows with replacement.
bootstrap_features (bool, default=False) – Sample features with replacement.
oob_score (bool, default=False) – Whether to compute out-of-bag accuracy.
n_jobs (int or None, default=None) – Parallel jobs.
-1uses all CPUs.random_state (int or None, default=None) – Random seed.
verbose (bool, default=False)
- oob_decision_function_¶
OOB predicted probabilities (only if
oob_score=True).- Type:
ndarray
- classes_¶
- Type:
ndarray
- property feature_importances_¶
Average feature importances across bags (original feature space).
- set_fit_request(*, sample_weight='$UNCHANGED$')¶
Configure whether metadata should be requested to be passed to the
fitmethod.Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with
enable_metadata_routing=True(seesklearn.set_config()). Please check the User Guide on how the routing mechanism works.The options for each parameter are:
True: metadata is requested, and passed tofitif provided. The request is ignored if metadata is not provided.False: metadata is not requested and the meta-estimator will not pass it tofit.None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.Added in version 1.3.
- Parameters:
sample_weight (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
sample_weightparameter infit.self (BaggingClassifier)
- Returns:
self (object) – The updated object.
- Return type:
- set_score_request(*, sample_weight='$UNCHANGED$')¶
Configure whether metadata should be requested to be passed to the
scoremethod.Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with
enable_metadata_routing=True(seesklearn.set_config()). Please check the User Guide on how the routing mechanism works.The options for each parameter are:
True: metadata is requested, and passed toscoreif provided. The request is ignored if metadata is not provided.False: metadata is not requested and the meta-estimator will not pass it toscore.None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.Added in version 1.3.
- Parameters:
sample_weight (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
sample_weightparameter inscore.self (BaggingClassifier)
- Returns:
self (object) – The updated object.
- Return type:
- class endgame.ensemble.BaggingRegressor(base_estimator=None, n_estimators=10, max_samples=1.0, max_features=1.0, bootstrap=True, bootstrap_features=False, oob_score=False, n_jobs=None, random_state=None, verbose=False)[source]¶
Bases:
BaseEstimator,RegressorMixinBootstrap Aggregating regressor.
- Parameters:
base_estimator (estimator, optional) – Base learner. Default:
DecisionTreeRegressor().n_estimators (int, default=10)
bootstrap (bool, default=True)
bootstrap_features (bool, default=False)
oob_score (bool, default=False)
n_jobs (int or None, default=None)
random_state (int or None, default=None)
verbose (bool, default=False)
- oob_prediction_¶
OOB predictions (only if
oob_score=True).- Type:
ndarray
- property feature_importances_¶
- set_fit_request(*, sample_weight='$UNCHANGED$')¶
Configure whether metadata should be requested to be passed to the
fitmethod.Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with
enable_metadata_routing=True(seesklearn.set_config()). Please check the User Guide on how the routing mechanism works.The options for each parameter are:
True: metadata is requested, and passed tofitif provided. The request is ignored if metadata is not provided.False: metadata is not requested and the meta-estimator will not pass it tofit.None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.Added in version 1.3.
- Parameters:
sample_weight (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
sample_weightparameter infit.self (BaggingRegressor)
- Returns:
self (object) – The updated object.
- Return type:
- set_score_request(*, sample_weight='$UNCHANGED$')¶
Configure whether metadata should be requested to be passed to the
scoremethod.Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with
enable_metadata_routing=True(seesklearn.set_config()). Please check the User Guide on how the routing mechanism works.The options for each parameter are:
True: metadata is requested, and passed toscoreif provided. The request is ignored if metadata is not provided.False: metadata is not requested and the meta-estimator will not pass it toscore.None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.Added in version 1.3.
- Parameters:
sample_weight (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
sample_weightparameter inscore.self (BaggingRegressor)
- Returns:
self (object) – The updated object.
- Return type:
- class endgame.ensemble.AdaBoostClassifier(base_estimator=None, n_estimators=50, learning_rate=1.0, algorithm='SAMME.R', random_state=None)[source]¶
Bases:
BaseEstimator,ClassifierMixinAdaBoost classifier (SAMME / SAMME.R).
- Parameters:
base_estimator (estimator, optional) – Base learner. Default:
DecisionTreeClassifier(max_depth=1)(stump).n_estimators (int, default=50) – Maximum number of boosting rounds.
learning_rate (float, default=1.0) – Shrinkage applied to each estimator’s weight. Lower values require more estimators but generalize better.
algorithm ({'SAMME', 'SAMME.R'}, default='SAMME.R') –
'SAMME': discrete AdaBoost using class labels.'SAMME.R': real AdaBoost using class probabilities (requirespredict_proba).
random_state (int or None, default=None)
- estimator_weights_¶
Weight of each estimator (SAMME only).
- Type:
ndarray
- estimator_errors_¶
Weighted error of each estimator.
- Type:
ndarray
- classes_¶
- Type:
ndarray
- feature_importances_¶
Sum of feature importances weighted by estimator weight.
- Type:
ndarray
- property feature_importances_¶
- set_fit_request(*, sample_weight='$UNCHANGED$')¶
Configure whether metadata should be requested to be passed to the
fitmethod.Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with
enable_metadata_routing=True(seesklearn.set_config()). Please check the User Guide on how the routing mechanism works.The options for each parameter are:
True: metadata is requested, and passed tofitif provided. The request is ignored if metadata is not provided.False: metadata is not requested and the meta-estimator will not pass it tofit.None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.Added in version 1.3.
- Parameters:
sample_weight (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
sample_weightparameter infit.self (AdaBoostClassifier)
- Returns:
self (object) – The updated object.
- Return type:
- set_score_request(*, sample_weight='$UNCHANGED$')¶
Configure whether metadata should be requested to be passed to the
scoremethod.Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with
enable_metadata_routing=True(seesklearn.set_config()). Please check the User Guide on how the routing mechanism works.The options for each parameter are:
True: metadata is requested, and passed toscoreif provided. The request is ignored if metadata is not provided.False: metadata is not requested and the meta-estimator will not pass it toscore.None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.Added in version 1.3.
- Parameters:
sample_weight (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
sample_weightparameter inscore.self (AdaBoostClassifier)
- Returns:
self (object) – The updated object.
- Return type:
- class endgame.ensemble.AdaBoostRegressor(base_estimator=None, n_estimators=50, learning_rate=1.0, loss='linear', random_state=None)[source]¶
Bases:
BaseEstimator,RegressorMixinAdaBoost.R2 regressor.
- Parameters:
- estimator_weights_¶
- Type:
ndarray
- estimator_errors_¶
- Type:
ndarray
- feature_importances_¶
- Type:
ndarray
- property feature_importances_¶
- set_fit_request(*, sample_weight='$UNCHANGED$')¶
Configure whether metadata should be requested to be passed to the
fitmethod.Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with
enable_metadata_routing=True(seesklearn.set_config()). Please check the User Guide on how the routing mechanism works.The options for each parameter are:
True: metadata is requested, and passed tofitif provided. The request is ignored if metadata is not provided.False: metadata is not requested and the meta-estimator will not pass it tofit.None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.Added in version 1.3.
- Parameters:
sample_weight (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
sample_weightparameter infit.self (AdaBoostRegressor)
- Returns:
self (object) – The updated object.
- Return type:
- set_score_request(*, sample_weight='$UNCHANGED$')¶
Configure whether metadata should be requested to be passed to the
scoremethod.Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with
enable_metadata_routing=True(seesklearn.set_config()). Please check the User Guide on how the routing mechanism works.The options for each parameter are:
True: metadata is requested, and passed toscoreif provided. The request is ignored if metadata is not provided.False: metadata is not requested and the meta-estimator will not pass it toscore.None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.Added in version 1.3.
- Parameters:
sample_weight (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
sample_weightparameter inscore.self (AdaBoostRegressor)
- Returns:
self (object) – The updated object.
- Return type:
- class endgame.ensemble.StackingEnsemble(base_estimators=None, meta_estimator=None, cv=5, passthrough=False, use_proba=True, stack_method='auto', random_state=None, verbose=False)[source]¶
Bases:
BaseEnsembleMulti-level stacking with out-of-fold prediction handling.
Level 1: Diverse base models (GBDTs, NNs, etc.) Level 2: Meta-learner (typically Ridge/Linear Regression)
The meta-learner is trained on out-of-fold predictions from Level 1 to prevent overfitting.
- Parameters:
base_estimators (List[estimator]) – Level 1 models.
meta_estimator (estimator, optional) – Level 2 model. Default: Ridge for regression, LogisticRegression for classification.
cv (int or CV splitter, default=5) – Cross-validation strategy for OOF predictions.
passthrough (bool, default=False) – Whether to include original features in Level 2.
use_proba (bool, default=True) – Use predict_proba for classification (if available).
stack_method (str, default='auto') – Method for stacking: ‘auto’, ‘predict’, ‘predict_proba’.
random_state (int, optional) – Random seed.
verbose (bool, default=False) – Enable verbose output.
- base_estimators_¶
Fitted Level 1 models.
- Type:
List[estimator]
- meta_estimator_¶
Fitted Level 2 model.
- Type:
estimator
- oof_predictions_¶
Out-of-fold predictions used for meta-learner training.
- Type:
ndarray
Examples
>>> from endgame.ensemble import StackingEnsemble >>> base_models = [LGBMWrapper(), XGBWrapper(), CatBoostWrapper()] >>> stacker = StackingEnsemble(base_estimators=base_models) >>> stacker.fit(X_train, y_train) >>> predictions = stacker.predict(X_test)
- fit(X, y, sample_weight=None, **fit_params)[source]¶
Fit the stacking ensemble.
- Parameters:
X (array-like of shape (n_samples, n_features)) – Training data.
y (array-like of shape (n_samples,)) – Target values.
sample_weight (array-like, optional) – Sample weights.
**fit_params – Additional parameters.
- Return type:
- Returns:
self
- predict(X)[source]¶
Predict using the stacking ensemble.
- Parameters:
X (array-like of shape (n_samples, n_features)) – Samples to predict.
- Return type:
- Returns:
ndarray – Predictions.
- predict_proba(X)[source]¶
Predict class probabilities.
- Parameters:
X (array-like of shape (n_samples, n_features)) – Samples to predict.
- Return type:
- Returns:
ndarray of shape (n_samples, n_classes) – Class probabilities.
- score(X, y, sample_weight=None)[source]¶
Return the mean accuracy on the given test data and labels.
For classification, this is the accuracy score. For regression, this is the R^2 score.
- Parameters:
X (array-like of shape (n_samples, n_features)) – Test samples.
y (array-like of shape (n_samples,)) – True labels for classification, true values for regression.
sample_weight (array-like of shape (n_samples,), optional) – Sample weights.
- Return type:
- Returns:
float – Score of the predictions.
- set_fit_request(*, sample_weight='$UNCHANGED$')¶
Configure whether metadata should be requested to be passed to the
fitmethod.Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with
enable_metadata_routing=True(seesklearn.set_config()). Please check the User Guide on how the routing mechanism works.The options for each parameter are:
True: metadata is requested, and passed tofitif provided. The request is ignored if metadata is not provided.False: metadata is not requested and the meta-estimator will not pass it tofit.None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.Added in version 1.3.
- Parameters:
sample_weight (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
sample_weightparameter infit.self (StackingEnsemble)
- Returns:
self (object) – The updated object.
- Return type:
- set_score_request(*, sample_weight='$UNCHANGED$')¶
Configure whether metadata should be requested to be passed to the
scoremethod.Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with
enable_metadata_routing=True(seesklearn.set_config()). Please check the User Guide on how the routing mechanism works.The options for each parameter are:
True: metadata is requested, and passed toscoreif provided. The request is ignored if metadata is not provided.False: metadata is not requested and the meta-estimator will not pass it toscore.None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.Added in version 1.3.
- Parameters:
sample_weight (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
sample_weightparameter inscore.self (StackingEnsemble)
- Returns:
self (object) – The updated object.
- Return type:
- class endgame.ensemble.BlendingEnsemble(base_estimators=None, meta_estimator=None, blend_fraction=0.2, use_proba=True, passthrough=False, cv=None, random_state=None, verbose=False)[source]¶
Bases:
BaseEnsemble,ClassifierMixinBlending Ensemble using hold-out set for meta-learner training.
Unlike stacking which uses cross-validation, blending uses a hold-out portion of the training data to generate meta-features for the second-level learner.
- Parameters:
base_estimators (List[estimator]) – Level 1 models.
meta_estimator (estimator, optional) – Level 2 model. Default: LogisticRegression for classification.
blend_fraction (float, default=0.2) – Fraction of training data to use for blending (meta-learner training).
use_proba (bool, default=True) – Use predict_proba for classification (if available).
passthrough (bool, default=False) – Whether to include original features in Level 2.
cv (int, optional) – Ignored. For API compatibility with StackingEnsemble.
random_state (int, optional) – Random seed.
verbose (bool, default=False) – Enable verbose output.
- base_estimators_¶
Fitted Level 1 models.
- Type:
List[estimator]
- meta_estimator_¶
Fitted Level 2 model.
- Type:
estimator
- classes_¶
Unique class labels (for classification).
- Type:
ndarray
Examples
>>> from endgame.ensemble import BlendingEnsemble >>> base_models = [RandomForestClassifier(), GradientBoostingClassifier()] >>> blender = BlendingEnsemble(base_estimators=base_models) >>> blender.fit(X_train, y_train) >>> predictions = blender.predict(X_test)
- fit(X, y, sample_weight=None, **fit_params)[source]¶
Fit the blending ensemble.
- Parameters:
X (array-like of shape (n_samples, n_features)) – Training data.
y (array-like of shape (n_samples,)) – Target values.
sample_weight (array-like, optional) – Sample weights.
- Return type:
- Returns:
self
- predict(X)[source]¶
Predict using the blending ensemble.
- Parameters:
X (array-like of shape (n_samples, n_features)) – Samples to predict.
- Return type:
- Returns:
ndarray – Predictions.
- predict_proba(X)[source]¶
Predict class probabilities.
- Parameters:
X (array-like of shape (n_samples, n_features)) – Samples to predict.
- Return type:
- Returns:
ndarray of shape (n_samples, n_classes) – Class probabilities.
- score(X, y, sample_weight=None)[source]¶
Return accuracy score on the given data.
- Parameters:
X (array-like of shape (n_samples, n_features)) – Test samples.
y (array-like of shape (n_samples,)) – True labels.
sample_weight (array-like, optional) – Sample weights.
- Return type:
- Returns:
float – Accuracy score.
- set_fit_request(*, sample_weight='$UNCHANGED$')¶
Configure whether metadata should be requested to be passed to the
fitmethod.Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with
enable_metadata_routing=True(seesklearn.set_config()). Please check the User Guide on how the routing mechanism works.The options for each parameter are:
True: metadata is requested, and passed tofitif provided. The request is ignored if metadata is not provided.False: metadata is not requested and the meta-estimator will not pass it tofit.None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.Added in version 1.3.
- Parameters:
sample_weight (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
sample_weightparameter infit.self (BlendingEnsemble)
- Returns:
self (object) – The updated object.
- Return type:
- set_score_request(*, sample_weight='$UNCHANGED$')¶
Configure whether metadata should be requested to be passed to the
scoremethod.Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with
enable_metadata_routing=True(seesklearn.set_config()). Please check the User Guide on how the routing mechanism works.The options for each parameter are:
True: metadata is requested, and passed toscoreif provided. The request is ignored if metadata is not provided.False: metadata is not requested and the meta-estimator will not pass it toscore.None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.Added in version 1.3.
- Parameters:
sample_weight (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
sample_weightparameter inscore.self (BlendingEnsemble)
- Returns:
self (object) – The updated object.
- Return type:
- class endgame.ensemble.OptimizedBlender(metric='roc_auc', n_trials=100, weight_bounds=(0, 1), normalize=True, maximize=True, random_state=None, verbose=False)[source]¶
Bases:
BaseEnsembleOptuna-powered blend weight optimization.
Uses Bayesian optimization to find optimal weights for combining model predictions.
- Parameters:
metric (str or callable) – Metric to optimize: ‘roc_auc’, ‘rmse’, ‘mae’, etc.
n_trials (int, default=100) – Number of optimization trials.
weight_bounds (Tuple[float, float], default=(0, 1)) – Bounds for individual model weights.
normalize (bool, default=True) – Whether weights must sum to 1.
maximize (bool, default=True) – Whether to maximize or minimize the metric.
random_state (int, optional) – Random seed.
verbose (bool, default=False) – Enable verbose output.
- study_¶
Optuna study object for further analysis.
- Type:
optuna.Study
Examples
>>> blender = OptimizedBlender(metric='roc_auc', n_trials=100) >>> blender.fit(oof_predictions, y_train) >>> final_pred = blender.predict(test_predictions)
- fit(predictions, y_true)[source]¶
Optimize blend weights using Optuna.
- Parameters:
predictions (List of arrays) – Out-of-fold predictions from each model.
y_true (array-like) – True target values.
- Return type:
- Returns:
self
- predict(predictions)[source]¶
Apply optimized weights.
- Parameters:
predictions (List of arrays) – Predictions from each model.
- Return type:
- Returns:
ndarray – Blended prediction.
- set_fit_request(*, predictions='$UNCHANGED$', y_true='$UNCHANGED$')¶
Configure whether metadata should be requested to be passed to the
fitmethod.Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with
enable_metadata_routing=True(seesklearn.set_config()). Please check the User Guide on how the routing mechanism works.The options for each parameter are:
True: metadata is requested, and passed tofitif provided. The request is ignored if metadata is not provided.False: metadata is not requested and the meta-estimator will not pass it tofit.None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.Added in version 1.3.
- Parameters:
predictions (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
predictionsparameter infit.y_true (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
y_trueparameter infit.self (OptimizedBlender)
- Returns:
self (object) – The updated object.
- Return type:
- set_predict_request(*, predictions='$UNCHANGED$')¶
Configure whether metadata should be requested to be passed to the
predictmethod.Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with
enable_metadata_routing=True(seesklearn.set_config()). Please check the User Guide on how the routing mechanism works.The options for each parameter are:
True: metadata is requested, and passed topredictif provided. The request is ignored if metadata is not provided.False: metadata is not requested and the meta-estimator will not pass it topredict.None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.Added in version 1.3.
- Parameters:
predictions (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
predictionsparameter inpredict.self (OptimizedBlender)
- Returns:
self (object) – The updated object.
- Return type:
- class endgame.ensemble.RankAverageBlender(method='average', normalize=True, weights=None, random_state=None, verbose=False)[source]¶
Bases:
BaseEnsembleRank-based blending for submissions.
Converts predictions to ranks before averaging. Robust to different prediction scales across models.
- Parameters:
Examples
>>> blender = RankAverageBlender() >>> final_pred = blender.blend(test_predictions)
- fit(predictions=None, y_true=None)[source]¶
Fit the blender (stores weights if provided).
- Parameters:
predictions (ignored)
y_true (ignored)
- Return type:
- Returns:
self
- blend(predictions)[source]¶
Blend predictions using rank averaging.
- Parameters:
predictions (List of arrays) – Predictions from each model.
- Return type:
- Returns:
ndarray – Rank-averaged prediction.
- set_fit_request(*, predictions='$UNCHANGED$', y_true='$UNCHANGED$')¶
Configure whether metadata should be requested to be passed to the
fitmethod.Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with
enable_metadata_routing=True(seesklearn.set_config()). Please check the User Guide on how the routing mechanism works.The options for each parameter are:
True: metadata is requested, and passed tofitif provided. The request is ignored if metadata is not provided.False: metadata is not requested and the meta-estimator will not pass it tofit.None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.Added in version 1.3.
- Parameters:
predictions (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
predictionsparameter infit.y_true (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
y_trueparameter infit.self (RankAverageBlender)
- Returns:
self (object) – The updated object.
- Return type:
- set_predict_request(*, predictions='$UNCHANGED$')¶
Configure whether metadata should be requested to be passed to the
predictmethod.Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with
enable_metadata_routing=True(seesklearn.set_config()). Please check the User Guide on how the routing mechanism works.The options for each parameter are:
True: metadata is requested, and passed topredictif provided. The request is ignored if metadata is not provided.False: metadata is not requested and the meta-estimator will not pass it topredict.None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.Added in version 1.3.
- Parameters:
predictions (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
predictionsparameter inpredict.self (RankAverageBlender)
- Returns:
self (object) – The updated object.
- Return type:
- class endgame.ensemble.PowerBlender(scores=None, power=2.0, higher_is_better=True, random_state=None, verbose=False)[source]¶
Bases:
BaseEnsemblePower-weighted blending based on individual scores.
Weights models by their validation scores raised to a power. Higher power = more weight to best models.
- Parameters:
Examples
>>> scores = [0.85, 0.87, 0.86] >>> blender = PowerBlender(scores=scores, power=3.0) >>> final_pred = blender.predict(test_predictions)
- fit(predictions=None, y_true=None, scores=None)[source]¶
Compute power-weighted blending weights.
- Parameters:
predictions (ignored)
y_true (ignored)
scores (List[float], optional) – Model scores (overrides constructor scores).
- Return type:
- Returns:
self
- predict(predictions)[source]¶
Apply power weights.
- Parameters:
predictions (List of arrays) – Predictions from each model.
- Return type:
- Returns:
ndarray – Power-weighted prediction.
- set_fit_request(*, predictions='$UNCHANGED$', scores='$UNCHANGED$', y_true='$UNCHANGED$')¶
Configure whether metadata should be requested to be passed to the
fitmethod.Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with
enable_metadata_routing=True(seesklearn.set_config()). Please check the User Guide on how the routing mechanism works.The options for each parameter are:
True: metadata is requested, and passed tofitif provided. The request is ignored if metadata is not provided.False: metadata is not requested and the meta-estimator will not pass it tofit.None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.Added in version 1.3.
- Parameters:
predictions (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
predictionsparameter infit.scores (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
scoresparameter infit.y_true (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
y_trueparameter infit.self (PowerBlender)
- Returns:
self (object) – The updated object.
- Return type:
- set_predict_request(*, predictions='$UNCHANGED$')¶
Configure whether metadata should be requested to be passed to the
predictmethod.Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with
enable_metadata_routing=True(seesklearn.set_config()). Please check the User Guide on how the routing mechanism works.The options for each parameter are:
True: metadata is requested, and passed topredictif provided. The request is ignored if metadata is not provided.False: metadata is not requested and the meta-estimator will not pass it topredict.None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.Added in version 1.3.
- Parameters:
predictions (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
predictionsparameter inpredict.self (PowerBlender)
- Returns:
self (object) – The updated object.
- Return type:
- class endgame.ensemble.HillClimbingEnsemble(metric='roc_auc', n_iterations=100, early_stopping=20, maximize=True, init_weights='best_single', random_state=None, verbose=False)[source]¶
Bases:
BaseEnsembleForward ensemble selection with replacement.
Iteratively adds models that maximize validation metric. Key technique for non-differentiable metrics (F1, MAP@K).
Algorithm: 1. Start with empty ensemble 2. For each iteration:
For each model in pool: - Compute metric if added to current ensemble
Add model that provides best improvement
Allow repeating models (weighted averaging)
- Parameters:
metric (str or callable, default='roc_auc') – Metric to optimize: ‘roc_auc’, ‘log_loss’, ‘f1’, ‘accuracy’, ‘rmse’, ‘mae’, ‘r2’, or custom callable(y_true, y_pred).
n_iterations (int, default=100) – Number of hill climbing iterations.
early_stopping (int, default=20) – Stop if no improvement for this many iterations.
maximize (bool, default=True) – Whether to maximize or minimize the metric.
init_weights (str, default='best_single') – Initial weight strategy: ‘best_single’, ‘uniform’, ‘none’.
random_state (int, optional) – Random seed for tie-breaking.
verbose (bool, default=False) – Enable verbose output.
Examples
>>> from endgame.ensemble import HillClimbingEnsemble >>> ensemble = HillClimbingEnsemble(metric='roc_auc', n_iterations=100) >>> ensemble.fit(oof_predictions, y_train) >>> print(f"Weights: {ensemble.weights_}") >>> test_pred = ensemble.predict(test_predictions)
- fit(predictions, y_true)[source]¶
Find optimal ensemble weights via hill climbing.
- Parameters:
predictions (List of shape (n_models, n_samples, ...)) – Out-of-fold predictions from each model.
y_true (array-like) – True target values.
- Return type:
- Returns:
self
- get_result()[source]¶
Get ensemble result summary.
- Return type:
EnsembleResult- Returns:
EnsembleResult – Result containing weights, score, and selected models.
- set_fit_request(*, predictions='$UNCHANGED$', y_true='$UNCHANGED$')¶
Configure whether metadata should be requested to be passed to the
fitmethod.Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with
enable_metadata_routing=True(seesklearn.set_config()). Please check the User Guide on how the routing mechanism works.The options for each parameter are:
True: metadata is requested, and passed tofitif provided. The request is ignored if metadata is not provided.False: metadata is not requested and the meta-estimator will not pass it tofit.None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.Added in version 1.3.
- Parameters:
predictions (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
predictionsparameter infit.y_true (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
y_trueparameter infit.self (HillClimbingEnsemble)
- Returns:
self (object) – The updated object.
- Return type:
- set_predict_request(*, predictions='$UNCHANGED$')¶
Configure whether metadata should be requested to be passed to the
predictmethod.Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with
enable_metadata_routing=True(seesklearn.set_config()). Please check the User Guide on how the routing mechanism works.The options for each parameter are:
True: metadata is requested, and passed topredictif provided. The request is ignored if metadata is not provided.False: metadata is not requested and the meta-estimator will not pass it topredict.None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.Added in version 1.3.
- Parameters:
predictions (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
predictionsparameter inpredict.self (HillClimbingEnsemble)
- Returns:
self (object) – The updated object.
- Return type:
- class endgame.ensemble.SuperLearner(base_estimators, meta_learner='nnls', cv=5, use_proba=True, include_original_features=False, random_state=None, verbose=False)[source]¶
Bases:
BaseEstimatorCross-validated Super Learner ensemble.
- Parameters:
base_estimators (list of (str, estimator) tuples) – Named base learners to combine.
meta_learner ({'nnls', 'ridge', 'best'} or estimator, default='nnls') – How to combine OOF predictions: -
'nnls': Non-negative least squares (convex combination). -'ridge': Ridge regression on OOF predictions. -'best': Use the single best base learner (no blending). - An sklearn estimator for custom meta-learning.cv (int or CV splitter, default=5) – Cross-validation strategy for OOF predictions.
use_proba (bool, default=True) – Use
predict_probafor classifiers (if available).include_original_features (bool, default=False) – Pass original features to the meta-learner alongside OOF predictions.
random_state (int or None, default=None)
verbose (bool, default=False)
- coef_¶
Meta-learner weights (one per base estimator).
- Type:
ndarray
- oof_predictions_¶
Out-of-fold predictions used for meta-learning.
- Type:
ndarray
References
van der Laan, M.J., Polley, E.C. & Hubbard, A.E. (2007). Super Learner. Statistical Applications in Genetics and Molecular Biology, 6(1).
- fit(X, y, sample_weight=None)[source]¶
Fit the Super Learner.
Generate OOF predictions for each base estimator.
Solve for optimal combination weights.
Refit all base estimators on the full training set.
- property named_estimators¶
- set_fit_request(*, sample_weight='$UNCHANGED$')¶
Configure whether metadata should be requested to be passed to the
fitmethod.Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with
enable_metadata_routing=True(seesklearn.set_config()). Please check the User Guide on how the routing mechanism works.The options for each parameter are:
True: metadata is requested, and passed tofitif provided. The request is ignored if metadata is not provided.False: metadata is not requested and the meta-estimator will not pass it tofit.None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.Added in version 1.3.
- Parameters:
sample_weight (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
sample_weightparameter infit.self (SuperLearner)
- Returns:
self (object) – The updated object.
- Return type:
- class endgame.ensemble.BayesianModelAveraging(criterion='bic', prior='uniform', task='auto')[source]¶
Bases:
BaseEstimatorBayesian Model Averaging using information-criterion weights.
- Parameters:
criterion ({'bic', 'aic', 'aic_c'}, default='bic') –
'bic': Bayesian Information Criterion (penalizes complexity more).'aic': Akaike Information Criterion.'aic_c': Corrected AIC for small samples.
prior ({'uniform', 'complexity'} or array-like, optional) – Prior over models. Default is uniform.
task ({'auto', 'classification', 'regression'}, default='auto')
- weights_¶
Posterior model weights summing to 1.
- Type:
ndarray
- ic_scores_¶
Information criterion values for each model.
- Type:
ndarray
- fit(estimators, X_val, y_val)[source]¶
Compute posterior weights from validation data.
- Parameters:
estimators (list of fitted estimators) – Already-fitted models.
X_val (array-like) – Validation features.
y_val (array-like) – Validation target.
- Return type:
- Returns:
self
- set_fit_request(*, X_val='$UNCHANGED$', estimators='$UNCHANGED$', y_val='$UNCHANGED$')¶
Configure whether metadata should be requested to be passed to the
fitmethod.Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with
enable_metadata_routing=True(seesklearn.set_config()). Please check the User Guide on how the routing mechanism works.The options for each parameter are:
True: metadata is requested, and passed tofitif provided. The request is ignored if metadata is not provided.False: metadata is not requested and the meta-estimator will not pass it tofit.None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.Added in version 1.3.
- Parameters:
X_val (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
X_valparameter infit.estimators (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
estimatorsparameter infit.y_val (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
y_valparameter infit.self (BayesianModelAveraging)
- Returns:
self (object) – The updated object.
- Return type:
- class endgame.ensemble.NegativeCorrelationEnsemble(base_estimators, lambda_ncl=0.5, n_iterations=10, weights=None, random_state=None, verbose=False)[source]¶
Bases:
BaseEstimator,RegressorMixinNegative Correlation Learning ensemble for regression.
Trains all base learners together, each with a modified loss that includes a diversity term penalizing correlation with the ensemble average. This produces models that are individually weaker but collectively stronger.
- Parameters:
base_estimators (list of estimator) – Base regressors to train. Must support
sample_weightor partial fit.lambda_ncl (float, default=0.5) – Strength of the negative correlation penalty. -
0: independent training (standard ensemble). -1: maximum diversity pressure.n_iterations (int, default=10) – Number of NCL training rounds.
weights (array-like, optional) – Static model weights. Default is uniform.
random_state (int or None, default=None)
verbose (bool, default=False)
- weights_¶
Model combination weights.
- Type:
ndarray
References
Liu, Y. & Yao, X. (1999). Ensemble Learning via Negative Correlation. Neural Networks, 12(10), 1399-1404.
- fit(X, y, sample_weight=None)[source]¶
Fit with negative correlation learning.
Each round: 1. Compute ensemble prediction (average of all learners). 2. For each learner i, compute modified sample weights
that up-weight samples where learner i disagrees with the ensemble (promoting diversity).
Refit each learner with the modified weights.
- property feature_importances_¶
- set_fit_request(*, sample_weight='$UNCHANGED$')¶
Configure whether metadata should be requested to be passed to the
fitmethod.Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with
enable_metadata_routing=True(seesklearn.set_config()). Please check the User Guide on how the routing mechanism works.The options for each parameter are:
True: metadata is requested, and passed tofitif provided. The request is ignored if metadata is not provided.False: metadata is not requested and the meta-estimator will not pass it tofit.None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.Added in version 1.3.
- Parameters:
sample_weight (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
sample_weightparameter infit.self (NegativeCorrelationEnsemble)
- Returns:
self (object) – The updated object.
- Return type:
- set_score_request(*, sample_weight='$UNCHANGED$')¶
Configure whether metadata should be requested to be passed to the
scoremethod.Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with
enable_metadata_routing=True(seesklearn.set_config()). Please check the User Guide on how the routing mechanism works.The options for each parameter are:
True: metadata is requested, and passed toscoreif provided. The request is ignored if metadata is not provided.False: metadata is not requested and the meta-estimator will not pass it toscore.None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.Added in version 1.3.
- Parameters:
sample_weight (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
sample_weightparameter inscore.self (NegativeCorrelationEnsemble)
- Returns:
self (object) – The updated object.
- Return type:
- class endgame.ensemble.SnapshotEnsemble(base_estimator, n_snapshots=5, epochs_per_cycle=40, initial_lr=0.1, min_lr=1e-05, verbose=False)[source]¶
Bases:
BaseEstimatorSnapshot Ensemble via cosine annealing warm restarts.
Trains a single neural-network-like estimator with a cyclic learning rate schedule. At the end of each cycle (when LR reaches its minimum), takes a “snapshot” of the model. The final ensemble averages predictions across all snapshots.
- Parameters:
base_estimator (estimator) – A model supporting
partial_fit(e.g.,MLPClassifier,SGDClassifier,SGDRegressor). Must acceptlearning_rate_initoreta0.n_snapshots (int, default=5) – Number of snapshots (cycles) to collect.
epochs_per_cycle (int, default=40) – Training epochs per cosine annealing cycle.
initial_lr (float, default=0.1) – Peak learning rate at the start of each cycle.
min_lr (float, default=1e-5) – Minimum learning rate at end of each cycle (snapshot point).
verbose (bool, default=False)
References
Huang, G., Li, Y., Pleiss, G., Liu, Z., Hopcroft, J.E., & Weinberger, K.Q. (2017). Snapshot Ensembles: Train 1, Get M for Free. ICLR.
- class endgame.ensemble.CascadeEnsemble(stages, confidence_threshold=0.95, cv=3, use_proba=True, passthrough=True, max_stages=None, random_state=None, verbose=False)[source]¶
Bases:
BaseEstimator,ClassifierMixinMulti-stage cascade classifier with early-exit.
- Parameters:
stages (list of list of estimator) – Each stage is a list of base classifiers. Predictions from stage k are concatenated as features for stage k+1.
confidence_threshold (float, default=0.95) – If max predicted probability exceeds this, the sample exits the cascade early (only at prediction time).
cv (int, default=3) – CV folds for generating OOF features during training.
use_proba (bool, default=True) – Use predicted probabilities as cascade features (vs. labels).
passthrough (bool, default=True) – Include original features at every stage.
max_stages (int or None, default=None) – Maximum number of stages. If None, use all provided stages.
random_state (int or None, default=None)
verbose (bool, default=False)
- classes_¶
- Type:
ndarray
- fit(X, y, sample_weight=None)[source]¶
Fit the cascade stage by stage.
At each stage, generate OOF predictions, concatenate them as features for the next stage, then refit on all data.
- predict_proba(X)[source]¶
Predict with early exit based on confidence.
Samples whose max probability exceeds
confidence_thresholdat any stage are assigned their prediction from that stage. Remaining samples proceed to the next stage.
- set_fit_request(*, sample_weight='$UNCHANGED$')¶
Configure whether metadata should be requested to be passed to the
fitmethod.Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with
enable_metadata_routing=True(seesklearn.set_config()). Please check the User Guide on how the routing mechanism works.The options for each parameter are:
True: metadata is requested, and passed tofitif provided. The request is ignored if metadata is not provided.False: metadata is not requested and the meta-estimator will not pass it tofit.None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.Added in version 1.3.
- Parameters:
sample_weight (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
sample_weightparameter infit.self (CascadeEnsemble)
- Returns:
self (object) – The updated object.
- Return type:
- set_score_request(*, sample_weight='$UNCHANGED$')¶
Configure whether metadata should be requested to be passed to the
scoremethod.Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with
enable_metadata_routing=True(seesklearn.set_config()). Please check the User Guide on how the routing mechanism works.The options for each parameter are:
True: metadata is requested, and passed toscoreif provided. The request is ignored if metadata is not provided.False: metadata is not requested and the meta-estimator will not pass it toscore.None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.Added in version 1.3.
- Parameters:
sample_weight (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
sample_weightparameter inscore.self (CascadeEnsemble)
- Returns:
self (object) – The updated object.
- Return type:
- class endgame.ensemble.ThresholdOptimizer(metric='f1', search_method='grid', n_thresholds=100, threshold_range=(0.1, 0.9), multiclass=False, random_state=None, verbose=False)[source]¶
Bases:
EndgameEstimatorOptimizes classification thresholds for target metrics.
Standard 0.5 threshold is often suboptimal. This optimizer finds per-class thresholds that maximize the target metric.
- Parameters:
metric (str or callable, default='f1') – Metric to optimize: ‘f1’, ‘f1_macro’, ‘f1_weighted’, ‘accuracy’, ‘balanced_accuracy’, or custom callable.
search_method (str, default='grid') – Search method: ‘grid’, ‘optuna’, ‘hill_climb’.
n_thresholds (int, default=100) – Number of thresholds to search (for grid search).
threshold_range (Tuple[float, float], default=(0.1, 0.9)) – Range of thresholds to search.
multiclass (bool, default=False) – Whether to optimize per-class thresholds.
random_state (int, optional) – Random seed.
verbose (bool, default=False) – Enable verbose output.
Examples
>>> optimizer = ThresholdOptimizer(metric='f1') >>> optimizer.fit(y_true, y_proba) >>> print(f"Optimal threshold: {optimizer.threshold_}") >>> y_pred = optimizer.predict(y_proba)
- fit(y_true, y_proba)[source]¶
Find optimal threshold(s).
- Parameters:
y_true (array-like) – True labels.
y_proba (array-like) – Predicted probabilities. Shape (n_samples,) for binary, (n_samples, n_classes) for multiclass.
- Return type:
- Returns:
self
- predict(y_proba)[source]¶
Apply optimized threshold(s) to predictions.
- Parameters:
y_proba (array-like) – Predicted probabilities.
- Return type:
- Returns:
ndarray – Predicted labels.
- set_fit_request(*, y_proba='$UNCHANGED$', y_true='$UNCHANGED$')¶
Configure whether metadata should be requested to be passed to the
fitmethod.Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with
enable_metadata_routing=True(seesklearn.set_config()). Please check the User Guide on how the routing mechanism works.The options for each parameter are:
True: metadata is requested, and passed tofitif provided. The request is ignored if metadata is not provided.False: metadata is not requested and the meta-estimator will not pass it tofit.None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.Added in version 1.3.
- Parameters:
y_proba (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
y_probaparameter infit.y_true (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
y_trueparameter infit.self (ThresholdOptimizer)
- Returns:
self (object) – The updated object.
- Return type:
- set_predict_request(*, y_proba='$UNCHANGED$')¶
Configure whether metadata should be requested to be passed to the
predictmethod.Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with
enable_metadata_routing=True(seesklearn.set_config()). Please check the User Guide on how the routing mechanism works.The options for each parameter are:
True: metadata is requested, and passed topredictif provided. The request is ignored if metadata is not provided.False: metadata is not requested and the meta-estimator will not pass it topredict.None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.Added in version 1.3.
- Parameters:
y_proba (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
y_probaparameter inpredict.self (ThresholdOptimizer)
- Returns:
self (object) – The updated object.
- Return type:
- set_transform_request(*, y_proba='$UNCHANGED$')¶
Configure whether metadata should be requested to be passed to the
transformmethod.Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with
enable_metadata_routing=True(seesklearn.set_config()). Please check the User Guide on how the routing mechanism works.The options for each parameter are:
True: metadata is requested, and passed totransformif provided. The request is ignored if metadata is not provided.False: metadata is not requested and the meta-estimator will not pass it totransform.None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.Added in version 1.3.
- Parameters:
y_proba (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
y_probaparameter intransform.self (ThresholdOptimizer)
- Returns:
self (object) – The updated object.
- Return type:
- class endgame.ensemble.KnowledgeDistiller(teacher, student, temperature=3.0, alpha=0.7, augment=False, augment_ratio=1.0, augment_swap_prob=0.1, random_state=None)[source]¶
Bases:
BaseEstimatorKnowledge distillation from teacher to student model.
Trains a simpler student model to mimic the predictions of a complex teacher model (or ensemble), enabling deployment of lightweight models with minimal accuracy loss.
- Parameters:
teacher (estimator) – Fitted teacher model. Must have predict_proba (classification) or predict (regression).
student (estimator) – Unfitted student model to train.
temperature (float, default=3.0) – Softmax temperature for soft label generation (classification only). Higher values produce softer probability distributions that reveal more about the teacher’s learned relationships.
alpha (float, default=0.7) – Weight for soft labels vs hard labels. Loss = alpha * soft_loss + (1 - alpha) * hard_loss. Set to 1.0 for pure distillation.
augment (bool, default=False) – Whether to use MUNGE data augmentation to generate additional training data labeled by the teacher.
augment_ratio (float, default=1.0) – Ratio of augmented samples to original samples.
augment_swap_prob (float, default=0.1) – Feature swap probability for MUNGE augmentation.
random_state (int or None, default=None) – Random state.
- student_¶
The trained student model.
- Type:
estimator
Example
>>> from sklearn.ensemble import RandomForestClassifier >>> from sklearn.linear_model import LogisticRegression >>> >>> teacher = RandomForestClassifier(n_estimators=500).fit(X, y) >>> distiller = KnowledgeDistiller( ... teacher=teacher, ... student=LogisticRegression(), ... temperature=4.0, ... alpha=0.8, ... augment=True ... ) >>> distiller.fit(X, y) >>> y_pred = distiller.predict(X_test)
- fit(X, y, **fit_params)[source]¶
Train the student model using knowledge distillation.
- Parameters:
X (array-like of shape (n_samples, n_features)) – Training features.
y (array-like of shape (n_samples,)) – True labels (hard targets).
- Return type:
- Returns:
self
- property feature_importances_¶
Feature importances from the student model.
- class endgame.ensemble.MultiOutputClassifier(estimator=None, n_jobs=None, random_state=None, verbose=False)[source]¶
Bases:
BaseEstimator,ClassifierMixinWraps a single-output classifier for multi-output classification.
Fits one independent clone of the base classifier per output column. Supports parallel fitting via joblib.
- Parameters:
estimator (estimator) – The base classifier to clone for each output. Must implement
fitandpredict.n_jobs (int, optional) – Number of jobs for parallel fitting.
Nonemeans 1 (sequential).-1means using all processors.random_state (int, optional) – Random seed. Passed to each cloned estimator if it accepts
random_state.verbose (bool, default=False) – Enable verbose output during fitting.
- estimators_¶
Fitted classifiers, one per output.
- Type:
List[estimator]
- classes_¶
Class labels for each output.
- Type:
List[ndarray]
Examples
>>> from endgame.ensemble.multi_output import MultiOutputClassifier >>> from sklearn.tree import DecisionTreeClassifier >>> import numpy as np >>> X = np.random.randn(100, 5) >>> Y = np.random.randint(0, 3, size=(100, 3)) >>> clf = MultiOutputClassifier(DecisionTreeClassifier(), n_jobs=-1) >>> clf.fit(X, Y) >>> preds = clf.predict(X) >>> preds.shape (100, 3)
- fit(X, Y, sample_weight=None)[source]¶
Fit one classifier per output column.
- Parameters:
X (array-like of shape (n_samples, n_features)) – Training features.
Y (array-like of shape (n_samples, n_outputs)) – Multi-output target matrix.
sample_weight (array-like of shape (n_samples,), optional) – Sample weights passed to each estimator.
- Returns:
self
- predict(X)[source]¶
Predict class labels for each output.
- Parameters:
X (array-like of shape (n_samples, n_features)) – Samples to predict.
- Returns:
ndarray of shape (n_samples, n_outputs) – Predicted class labels.
- predict_proba(X)[source]¶
Predict class probabilities for each output.
- Parameters:
X (array-like of shape (n_samples, n_features)) – Samples to predict.
- Returns:
list of ndarray – List of length
n_outputs_, where each element is an array of shape(n_samples, n_classes_k)containing class probabilities for output k.
- score(X, Y, sample_weight=None)[source]¶
Return the mean accuracy across all outputs.
- Parameters:
X (array-like of shape (n_samples, n_features)) – Test samples.
Y (array-like of shape (n_samples, n_outputs)) – True labels.
sample_weight (array-like, optional) – Sample weights.
- Returns:
float – Mean of per-output accuracy scores.
- set_fit_request(*, sample_weight='$UNCHANGED$')¶
Configure whether metadata should be requested to be passed to the
fitmethod.Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with
enable_metadata_routing=True(seesklearn.set_config()). Please check the User Guide on how the routing mechanism works.The options for each parameter are:
True: metadata is requested, and passed tofitif provided. The request is ignored if metadata is not provided.False: metadata is not requested and the meta-estimator will not pass it tofit.None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.Added in version 1.3.
- Parameters:
sample_weight (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
sample_weightparameter infit.self (MultiOutputClassifier)
- Returns:
self (object) – The updated object.
- Return type:
- set_score_request(*, sample_weight='$UNCHANGED$')¶
Configure whether metadata should be requested to be passed to the
scoremethod.Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with
enable_metadata_routing=True(seesklearn.set_config()). Please check the User Guide on how the routing mechanism works.The options for each parameter are:
True: metadata is requested, and passed toscoreif provided. The request is ignored if metadata is not provided.False: metadata is not requested and the meta-estimator will not pass it toscore.None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.Added in version 1.3.
- Parameters:
sample_weight (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
sample_weightparameter inscore.self (MultiOutputClassifier)
- Returns:
self (object) – The updated object.
- Return type:
- class endgame.ensemble.MultiOutputRegressor(estimator=None, n_jobs=None, random_state=None, verbose=False)[source]¶
Bases:
BaseEstimator,RegressorMixinWraps a single-output regressor for multi-output regression.
Fits one independent clone of the base regressor per output column. Supports parallel fitting via joblib.
- Parameters:
estimator (estimator) – The base regressor to clone for each output. Must implement
fitandpredict.n_jobs (int, optional) – Number of jobs for parallel fitting.
Nonemeans 1 (sequential).-1means using all processors.random_state (int, optional) – Random seed. Passed to each cloned estimator if it accepts
random_state.verbose (bool, default=False) – Enable verbose output during fitting.
- estimators_¶
Fitted regressors, one per output.
- Type:
List[estimator]
Examples
>>> from endgame.ensemble.multi_output import MultiOutputRegressor >>> from sklearn.linear_model import Ridge >>> import numpy as np >>> X = np.random.randn(100, 5) >>> Y = np.random.randn(100, 3) >>> reg = MultiOutputRegressor(Ridge(), n_jobs=-1) >>> reg.fit(X, Y) >>> preds = reg.predict(X) >>> preds.shape (100, 3)
- fit(X, Y, sample_weight=None)[source]¶
Fit one regressor per output column.
- Parameters:
X (array-like of shape (n_samples, n_features)) – Training features.
Y (array-like of shape (n_samples, n_outputs)) – Multi-output target matrix.
sample_weight (array-like of shape (n_samples,), optional) – Sample weights passed to each estimator.
- Returns:
self
- predict(X)[source]¶
Predict target values for each output.
- Parameters:
X (array-like of shape (n_samples, n_features)) – Samples to predict.
- Returns:
ndarray of shape (n_samples, n_outputs) – Predicted values.
- property feature_importances_¶
Average feature importances across all output estimators.
- Returns:
ndarray of shape (n_features,) – Mean of
feature_importances_across fitted estimators.- Raises:
AttributeError – If the base estimators do not expose
feature_importances_.
- score(X, Y, sample_weight=None)[source]¶
Return the mean R^2 score across all outputs.
- Parameters:
X (array-like of shape (n_samples, n_features)) – Test samples.
Y (array-like of shape (n_samples, n_outputs)) – True target values.
sample_weight (array-like, optional) – Sample weights.
- Returns:
float – Mean of per-output R^2 scores.
- set_fit_request(*, sample_weight='$UNCHANGED$')¶
Configure whether metadata should be requested to be passed to the
fitmethod.Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with
enable_metadata_routing=True(seesklearn.set_config()). Please check the User Guide on how the routing mechanism works.The options for each parameter are:
True: metadata is requested, and passed tofitif provided. The request is ignored if metadata is not provided.False: metadata is not requested and the meta-estimator will not pass it tofit.None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.Added in version 1.3.
- Parameters:
sample_weight (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
sample_weightparameter infit.self (MultiOutputRegressor)
- Returns:
self (object) – The updated object.
- Return type:
- set_score_request(*, sample_weight='$UNCHANGED$')¶
Configure whether metadata should be requested to be passed to the
scoremethod.Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with
enable_metadata_routing=True(seesklearn.set_config()). Please check the User Guide on how the routing mechanism works.The options for each parameter are:
True: metadata is requested, and passed toscoreif provided. The request is ignored if metadata is not provided.False: metadata is not requested and the meta-estimator will not pass it toscore.None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.Added in version 1.3.
- Parameters:
sample_weight (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
sample_weightparameter inscore.self (MultiOutputRegressor)
- Returns:
self (object) – The updated object.
- Return type:
- class endgame.ensemble.ClassifierChain(estimator=None, order='auto', n_jobs=None, random_state=None, verbose=False)[source]¶
Bases:
BaseEstimator,ClassifierMixinChain classifiers where each uses predictions of previous outputs as features.
Each classifier in the chain receives the original feature matrix X augmented with the predictions from all preceding classifiers. This allows the chain to model dependencies between outputs.
- Parameters:
estimator (estimator) – The base classifier to clone for each link in the chain.
order (str or list of int, default='auto') –
Chain ordering strategy: -
'auto': greedy ordering by pairwise correlation so thatadjacent outputs in the chain are maximally correlated.
'random': random permutation (seeded byrandom_state).list of int: explicit column ordering.
n_jobs (int, optional) – Not used directly (chain is inherently sequential), but stored for API consistency.
random_state (int, optional) – Random seed for random ordering and estimator cloning.
verbose (bool, default=False) – Enable verbose output.
- estimators_¶
Fitted classifiers in chain order.
- Type:
List[estimator]
- classes_¶
Class labels for each output (in original column order).
- Type:
List[ndarray]
Examples
>>> from endgame.ensemble.multi_output import ClassifierChain >>> from sklearn.linear_model import LogisticRegression >>> import numpy as np >>> X = np.random.randn(200, 5) >>> Y = np.random.randint(0, 2, size=(200, 3)) >>> chain = ClassifierChain(LogisticRegression(), order='auto') >>> chain.fit(X, Y) >>> preds = chain.predict(X) >>> preds.shape (200, 3)
- fit(X, Y, sample_weight=None)[source]¶
Fit the classifier chain.
- Parameters:
X (array-like of shape (n_samples, n_features)) – Training features.
Y (array-like of shape (n_samples, n_outputs)) – Multi-output target matrix.
sample_weight (array-like of shape (n_samples,), optional) – Sample weights.
- Returns:
self
- predict(X)[source]¶
Predict class labels for each output.
At prediction time, the chain uses its own predictions (rather than ground truth) for augmentation.
- Parameters:
X (array-like of shape (n_samples, n_features)) – Samples to predict.
- Returns:
ndarray of shape (n_samples, n_outputs) – Predicted class labels in original column order.
- predict_proba(X)[source]¶
Predict class probabilities for each output.
- Parameters:
X (array-like of shape (n_samples, n_features)) – Samples to predict.
- Returns:
list of ndarray – List of length
n_outputs_(in original column order), where each element is an array of shape(n_samples, n_classes_k).
- score(X, Y, sample_weight=None)[source]¶
Return the mean accuracy across all outputs.
- Parameters:
X (array-like of shape (n_samples, n_features)) – Test samples.
Y (array-like of shape (n_samples, n_outputs)) – True labels.
sample_weight (array-like, optional) – Sample weights.
- Returns:
float – Mean of per-output accuracy scores.
- set_fit_request(*, sample_weight='$UNCHANGED$')¶
Configure whether metadata should be requested to be passed to the
fitmethod.Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with
enable_metadata_routing=True(seesklearn.set_config()). Please check the User Guide on how the routing mechanism works.The options for each parameter are:
True: metadata is requested, and passed tofitif provided. The request is ignored if metadata is not provided.False: metadata is not requested and the meta-estimator will not pass it tofit.None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.Added in version 1.3.
- Parameters:
sample_weight (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
sample_weightparameter infit.self (ClassifierChain)
- Returns:
self (object) – The updated object.
- Return type:
- set_score_request(*, sample_weight='$UNCHANGED$')¶
Configure whether metadata should be requested to be passed to the
scoremethod.Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with
enable_metadata_routing=True(seesklearn.set_config()). Please check the User Guide on how the routing mechanism works.The options for each parameter are:
True: metadata is requested, and passed toscoreif provided. The request is ignored if metadata is not provided.False: metadata is not requested and the meta-estimator will not pass it toscore.None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.Added in version 1.3.
- Parameters:
sample_weight (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
sample_weightparameter inscore.self (ClassifierChain)
- Returns:
self (object) – The updated object.
- Return type:
- class endgame.ensemble.RegressorChain(estimator=None, order='auto', n_jobs=None, random_state=None, verbose=False)[source]¶
Bases:
BaseEstimator,RegressorMixinChain regressors where each uses predictions of previous outputs as features.
Each regressor in the chain receives the original feature matrix X augmented with the predictions from all preceding regressors. This allows the chain to model dependencies between outputs.
- Parameters:
estimator (estimator) – The base regressor to clone for each link in the chain.
order (str or list of int, default='auto') –
Chain ordering strategy: -
'auto': greedy ordering by pairwise correlation so thatadjacent outputs in the chain are maximally correlated.
'random': random permutation (seeded byrandom_state).list of int: explicit column ordering.
n_jobs (int, optional) – Not used directly (chain is inherently sequential), but stored for API consistency.
random_state (int, optional) – Random seed for random ordering and estimator cloning.
verbose (bool, default=False) – Enable verbose output.
- estimators_¶
Fitted regressors in chain order.
- Type:
List[estimator]
Examples
>>> from endgame.ensemble.multi_output import RegressorChain >>> from sklearn.linear_model import Ridge >>> import numpy as np >>> X = np.random.randn(200, 5) >>> Y = np.random.randn(200, 3) >>> chain = RegressorChain(Ridge(), order='auto') >>> chain.fit(X, Y) >>> preds = chain.predict(X) >>> preds.shape (200, 3)
- fit(X, Y, sample_weight=None)[source]¶
Fit the regressor chain.
- Parameters:
X (array-like of shape (n_samples, n_features)) – Training features.
Y (array-like of shape (n_samples, n_outputs)) – Multi-output target matrix.
sample_weight (array-like of shape (n_samples,), optional) – Sample weights.
- Returns:
self
- predict(X)[source]¶
Predict target values for each output.
At prediction time, the chain uses its own predictions (rather than ground truth) for augmentation.
- Parameters:
X (array-like of shape (n_samples, n_features)) – Samples to predict.
- Returns:
ndarray of shape (n_samples, n_outputs) – Predicted values in original column order.
- property feature_importances_¶
Average feature importances across chain estimators.
Only includes importances for the original features (not the chained predictions), averaged across all estimators.
- Returns:
ndarray of shape (n_features,) – Mean feature importances for the original features.
- Raises:
AttributeError – If the base estimators do not expose
feature_importances_.
- score(X, Y, sample_weight=None)[source]¶
Return the mean R^2 score across all outputs.
- Parameters:
X (array-like of shape (n_samples, n_features)) – Test samples.
Y (array-like of shape (n_samples, n_outputs)) – True target values.
sample_weight (array-like, optional) – Sample weights.
- Returns:
float – Mean of per-output R^2 scores.
- set_fit_request(*, sample_weight='$UNCHANGED$')¶
Configure whether metadata should be requested to be passed to the
fitmethod.Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with
enable_metadata_routing=True(seesklearn.set_config()). Please check the User Guide on how the routing mechanism works.The options for each parameter are:
True: metadata is requested, and passed tofitif provided. The request is ignored if metadata is not provided.False: metadata is not requested and the meta-estimator will not pass it tofit.None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.Added in version 1.3.
- Parameters:
sample_weight (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
sample_weightparameter infit.self (RegressorChain)
- Returns:
self (object) – The updated object.
- Return type:
- set_score_request(*, sample_weight='$UNCHANGED$')¶
Configure whether metadata should be requested to be passed to the
scoremethod.Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with
enable_metadata_routing=True(seesklearn.set_config()). Please check the User Guide on how the routing mechanism works.The options for each parameter are:
True: metadata is requested, and passed toscoreif provided. The request is ignored if metadata is not provided.False: metadata is not requested and the meta-estimator will not pass it toscore.None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.Added in version 1.3.
- Parameters:
sample_weight (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for
sample_weightparameter inscore.self (RegressorChain)
- Returns:
self (object) – The updated object.
- Return type: