Regression API¶
- class stagecoachml.StagecoachRegressor(encoder, estimator, *, upstream_features, online_features, cv=None, residual=False)[source]¶
Bases:
RegressorMixin,StagecoachBaseCompose an upstream encoder with an online regressor.
- Parameters:
encoder (Any) – Transformer, PredictionEncoder, or frozen fitted transformer.
estimator (Any) – Online regressor exposing fit and predict.
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.
cv (Any) – Optional fold count or splitter for PredictionEncoder cross-fitting.
residual (bool) – If True, require one encoded prediction column, train the online estimator on its residual, and add that prediction back when serving.
- encoder_¶
Fitted upstream transformer.
- estimator_¶
Fitted online regressor.
- predictor_¶
Encoder-free online serving artifact.
- training_indices_¶
Rows used to fit the downstream regressor.
- encoder_id_¶
Unique identifier for this fitted representation contract.
- __init__(encoder, estimator, *, upstream_features, online_features, cv=None, residual=False)[source]¶
- fit(X, y, sample_weight=None, *, groups=None)[source]¶
Fit the encoder and online regressor.
- Parameters:
X (Any) – Full training feature matrix.
y (Any) – Single-output regression targets.
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 regressor.
- Return type:
- 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: