saealib.SklearnClassificationSurrogate#

class saealib.SklearnClassificationSurrogate(estimator)[source]#

Bases: ComparisonSurrogate

Surrogate adapter for scikit-learn compatible binary classifiers.

Wraps any estimator that implements fit(X, y) and predict_proba(X). train_y must be binary labels {0, 1}.

Parameters:

estimator (sklearn estimator) – A scikit-learn compatible classifier with predict_proba support (e.g. SVC(probability=True) or RandomForestClassifier()).

Raises:

ImportError – If scikit-learn is not installed.

Methods

__init__

contract

Return the surrogate model contract.

fit

Fit the classifier.

post_fit

Post-fit lifecycle hook; override to inject custom processing.

predict

Delegate to predict_proba.

predict_proba

Return class-1 probability estimates.

with_post_fit

Return a copy of this surrogate with fn appended to the post-fit hook.

Method Details

SklearnClassificationSurrogate.__init__(estimator)[source]#
Parameters:

estimator (object)

Return type:

None

SklearnClassificationSurrogate.contract()#

Return the surrogate model contract.

Return type:

ComponentContract

SklearnClassificationSurrogate.fit(train_x, train_y)[source]#

Fit the classifier.

Parameters:
  • train_x (np.ndarray) – Training input data. shape: (n_samples, n_features)

  • train_y (np.ndarray) – Binary labels. shape: (n_samples,), values in {0, 1}.

Return type:

None

SklearnClassificationSurrogate.post_fit(train_x, train_y, ctx=None)#

Post-fit lifecycle hook; override to inject custom processing.

Parameters:
  • train_x (np.ndarray) – Training input data used for this fit. shape: (n_samples, n_features)

  • train_y (np.ndarray) – Training output data used for this fit. shape: (n_samples, n_obj)

  • ctx (OptimizationState or None, optional) – Current optimization context.

Return type:

None

SklearnClassificationSurrogate.predict(test_x)#

Delegate to predict_proba.

Parameters:

test_x (ndarray)

Return type:

SurrogatePrediction

SklearnClassificationSurrogate.predict_proba(test_x)[source]#

Return class-1 probability estimates.

Parameters:

test_x (np.ndarray) – Input data. shape: (n_samples, n_features) or (n_features,)

Returns:

value shape: (n_samples, 1), values in [0, 1].

Return type:

SurrogatePrediction

SklearnClassificationSurrogate.with_post_fit(fn)#

Return a copy of this surrogate with fn appended to the post-fit hook.

Parameters:

fn (callable) – fn(train_x, train_y, ctx) -> None

Returns:

Shallow copy with the hook registered.

Return type:

Surrogate