stable_cart.RepresentativeEstimator

class stable_cart.RepresentativeEstimator(estimator=None, task='classification', n_candidates=20, proximity_metric='auto', validation_fraction=0.2, bootstrap_candidates=True, random_state=None)[source]

Select one fitted estimator closest to a candidate-pool centroid.

Candidates are fitted to independent bootstrap samples of a training split; classification candidates use class-stratified samples. The candidate closest to their mean prediction on a held-out selection split is retained. This produces one fitted estimator representative of that finite pool. It does not promise lower sampling instability than an unselected fit.

With squared Euclidean distance, choosing the candidate closest to the mean is equivalent to choosing the prediction medoid: the candidate with the smallest average squared distance to every other candidate. This implements representative-model selection; it is not a new algorithm.

Parameters

estimator

Unfitted scikit-learn-compatible estimator to clone for each candidate. The default is the corresponding scikit-learn decision tree.

task

"classification" or "regression".

n_candidates

Number of fitted candidates.

proximity_metric

"auto" uses RMSE for regression and probability MSE for classifiers with predict_proba (otherwise label disagreement). Explicit metrics must be compatible with the task.

validation_fraction

Fraction held out from candidate fitting for candidate selection.

bootstrap_candidates

Whether to bootstrap the candidate-fitting split. If false, deterministic base estimators can produce an identical candidate pool.

random_state

Random seed controlling the split, bootstrap samples, and candidate seeds.

__init__(estimator=None, task='classification', n_candidates=20, proximity_metric='auto', validation_fraction=0.2, bootstrap_candidates=True, random_state=None)[source]
Parameters:
  • estimator (Any | None)

  • task (Literal['classification', 'regression'])

  • n_candidates (int)

  • proximity_metric (Literal['auto', 'rmse', 'mae', 'correlation', 'disagreement', 'probability_mse'])

  • validation_fraction (float)

  • bootstrap_candidates (bool)

  • random_state (int | None)

Methods

__init__([estimator, task, n_candidates, ...])

fit(X, y)

Fit the candidate pool, select its representative, and return self.

get_metadata_routing()

Get metadata routing of this object.

get_params([deep])

Get parameters for this estimator.

get_selected_estimator()

Return the fitted candidate selected by the proximity rule.

predict(X)

Predict with the selected candidate estimator.

predict_proba(X)

Return aligned class probabilities from the selected classifier.

score(X, y[, sample_weight])

Return accuracy for classification or R-squared for regression.

set_params(**params)

Set the parameters of this estimator.

set_score_request(*[, sample_weight])

Configure whether metadata should be requested to be passed to the score method.

Parameters:
  • estimator (Any | None)

  • task (Literal['classification', 'regression'])

  • n_candidates (int)

  • proximity_metric (Literal['auto', 'rmse', 'mae', 'correlation', 'disagreement', 'probability_mse'])

  • validation_fraction (float)

  • bootstrap_candidates (bool)

  • random_state (int | None)