Classification API¶
- class stagecoachml.StagecoachClassifier(encoder, estimator, *, upstream_features, online_features, cv=None)[source]¶
Bases:
ClassifierMixin,StagecoachBaseCompose 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:
- 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:
- __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:
- Returns:
Versioned representations for downstream serving.
- Raises:
ValueError – If input or representation dimensions differ from training.
- Return type:
- predict(X)¶
Run both stages for ordinary scikit-learn evaluation.
- 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: