Classification API

class stagecoachml.StagecoachClassifier(encoder, estimator, *, upstream_features, online_features, cv=None)[source]

Bases: ClassifierMixin, StagecoachBase

Compose an upstream encoder with an online probabilistic classifier.

Parameters:
  • encoder (Any) – A transformer exposing fit/transform, a PredictionEncoder, or a fitted transformer wrapped in sklearn.frozen.FrozenEstimator.

  • estimator (Any) – Online classifier exposing fit, predict and predict_proba.

  • upstream_features (list[str] | list[int]) – Explicit upstream column names or integer positions.

  • online_features (list[str] | list[int]) – Explicit online column names or integer positions. Use an empty list when only representations are needed.

  • cv (Any) – Optional fold count or splitter for PredictionEncoder cross-fitting. Rows never held out are excluded from downstream training. None fits both stages on the supplied rows; supervised encoders may overfit.

encoder_

Fitted upstream transformer.

estimator_

Fitted online classifier.

predictor_

Encoder-free online serving artifact.

classes_

Downstream class labels in probability-column order.

training_indices_

Rows used to fit the downstream classifier.

encoder_id_

Unique identifier for this fitted representation contract.

fit(X, y, sample_weight=None, *, groups=None)[source]

Fit the encoder and online classifier.

Parameters:
  • X (Any) – Full training feature matrix.

  • y (Any) – Single-output classification labels.

  • sample_weight (ndarray | None) – Optional nonnegative weights, forwarded to both trainable components and sliced consistently within cross-fitting folds.

  • groups (Any) – Optional group labels for the supplied cross-validation splitter.

Returns:

The fitted classifier.

Return type:

StagecoachClassifier

predict_proba_from_state(X_online, state, *, state_indices=None, as_of=None, max_age=None)[source]

Predict probabilities without accessing the upstream encoder.

Parameters:
  • X_online (Any) – Online features only, one row per candidate.

  • state (EncodedState) – State produced by this fitted model.

  • state_indices (Any) – Optional representation row per candidate.

  • as_of (Any) – Optional request timestamps in Unix seconds.

  • max_age (float | None) – Optional maximum feature age in seconds.

Returns:

Probabilities in classes_ order, including two columns for binary tasks.

Return type:

ndarray

predict_proba(X)[source]

Run both stages and return final probabilities.

Parameters:

X (Any) – Full feature matrix with the fitted training schema.

Returns:

Probabilities in classes_ order.

Return type:

ndarray

__init__(encoder, estimator, *, upstream_features, online_features, cv=None)
encode(X_upstream, *, entity_ids=None, feature_times=None)

Prepare reusable state using only upstream inputs.

Parameters:
  • X_upstream (Any) – Upstream columns. DataFrame columns are selected by fitted name; arrays must contain only upstream columns in fitted order.

  • entity_ids (Any) – Optional unique identifiers, one per upstream row.

  • feature_times (Any) – Optional input cutoff timestamps in Unix seconds.

Returns:

Versioned representations for downstream serving.

Raises:

ValueError – If input or representation dimensions differ from training.

Return type:

EncodedState

predict(X)

Run both stages for ordinary scikit-learn evaluation.

Parameters:

X (Any) – Full feature matrix with the fitted training schema.

Returns:

Final predictions, one per input row.

Return type:

ndarray

predict_from_state(X_online, state, *, state_indices=None, as_of=None, max_age=None)

Predict using prepared state without executing or accessing the encoder.

Parameters:
  • X_online (Any) – Online features only, one row per candidate.

  • state (EncodedState) – Representations produced by this fitted model.

  • state_indices (Any) – Representation row per candidate; defaults to row alignment.

  • as_of (Any) – Optional request timestamps in Unix seconds.

  • max_age (float | None) – Optional maximum feature age in seconds.

Returns:

Final predictions, one per candidate.

Return type:

ndarray

feature_names_in_: ndarray