Representations and serving¶
- class stagecoachml.PredictionEncoder(estimator, *, method='auto')[source]¶
Bases:
TransformerMixin,BaseEstimatorExpose prediction scores as a two-dimensional representation.
- Parameters:
- estimator_¶
Fitted predictor.
- method_¶
Resolved prediction method.
- classes_¶
Class order when the predictor exposes classes.
- fit(X, y, sample_weight=None)[source]¶
Fit the predictor on upstream data.
- Parameters:
- Returns:
The fitted encoder.
- Raises:
ValueError – If the selected prediction method is unsupported.
- Return type:
- set_fit_request(*, sample_weight='$UNCHANGED$')¶
Configure whether metadata should be requested to be passed to the
fitmethod.Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with
enable_metadata_routing=True(seesklearn.set_config()). Please check the User Guide on how the routing mechanism works.The options for each parameter are:
True: metadata is requested, and passed tofitif provided. The request is ignored if metadata is not provided.False: metadata is not requested and the meta-estimator will not pass it tofit.None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.Added in version 1.3.
Parameters¶
- sample_weightstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED
Metadata routing for
sample_weightparameter infit.
Returns¶
- selfobject
The updated object.
- class stagecoachml.EncodedState(values, encoder_id, entity_ids=None, feature_times=None)[source]¶
Bases:
objectA versioned, dense representation batch with optional entity and time metadata.
Arrays are copied and made read-only. Store this object alongside its fitted model using ordinary Python serialization. The encoder identifier binds state to a particular model fit, including after serialization.
- Parameters:
values (ndarray) – Finite numeric matrix, one row per entity or observation.
encoder_id (str) – Identifier of the fitted encoder that produced these values.
entity_ids (ndarray | None) – Optional unique, nonmissing identifiers in representation order.
feature_times (ndarray | None) – Optional feature cutoff times in Unix seconds, scalar or one per representation. These describe input freshness, not write time.
- rows_for(entity_ids)[source]¶
Map candidate entity identifiers to representation rows, preserving order.
- Parameters:
entity_ids (object) – One entity identifier per candidate; repeats are allowed.
- Returns:
Integer row indices suitable for
predict_from_state.- Raises:
ValueError – If state has no entity identifiers or a candidate is missing.
- Return type:
- select(indices, *, as_of=None, max_age=None)[source]¶
Select rows and optionally enforce feature freshness.
- Parameters:
indices (object) – Positional representation rows, one per candidate.
as_of (object) – Request times in Unix seconds, scalar or one per candidate. Providing this rejects representations from the future.
max_age (float | None) – Maximum allowed age in seconds; requires
as_ofand stored feature times. The boundary is inclusive.
- Returns:
Representation rows aligned with the candidates.
- Raises:
ValueError – If indices, timestamps, or freshness constraints are invalid.
- Return type:
- __init__(values, encoder_id, entity_ids=None, feature_times=None)¶
- class stagecoachml.OnlinePredictor(estimator, encoder_id, n_encoded_features, n_online_features, online_names=None, residual=False)[source]¶
Bases:
objectServe a fitted downstream estimator without loading its upstream encoder.
Obtain this object from
model.predictor_after fitting. Serialize it with the prepared state for deployment in an independent process.- Parameters:
estimator (Any) – Fitted downstream estimator.
encoder_id (str) – Accepted fitted encoder identifier.
n_encoded_features (int) – Expected representation width.
n_online_features (int) – Expected number of online input columns.
online_names (tuple | None) – Fitted online column names, if trained on a DataFrame.
residual (bool) – Whether to add the first representation column to predictions.
- predict(X_online, state, *, state_indices=None, as_of=None, max_age=None)[source]¶
Score online inputs using an explicitly supplied representation batch.
- Parameters:
X_online (Any) – Numeric online features, one row per candidate.
state (EncodedState) – State from the matching encoder fit.
state_indices (Any) – Optional representation row per candidate.
as_of (Any) – Optional request times in Unix seconds, scalar or per candidate.
max_age (float | None) – Optional maximum feature age in seconds.
- Returns:
Predicted labels or regression values.
- Return type:
- predict_proba(X_online, state, *, state_indices=None, as_of=None, max_age=None)[source]¶
Return probabilities in the fitted downstream estimator’s class order.
- Parameters:
X_online (Any) – Numeric online features, one row per candidate.
state (EncodedState) – State from the matching encoder fit.
state_indices (Any) – Optional representation row per candidate.
as_of (Any) – Optional request times in Unix seconds, scalar or per candidate.
max_age (float | None) – Optional maximum feature age in seconds.
- Returns:
Probabilities with one column per class, including binary problems.
- Return type:
- __init__(estimator, encoder_id, n_encoded_features, n_online_features, online_names=None, residual=False)¶