polars_online.spec.output_index

polars_online.spec.output_index(spec: dict[str, Any]) → DataFrame[source]

List every field a spec writes, with the values its name encodes.

Use it to reach a field without building its name by hand, by filtering on what the field is about, such as its target, its ridge value and its half-life. For the names alone, use output_fields(), and for each coefficient’s place in a coef list, coef_fields().

Parameters

spec

A spec, as a builder of polars_online.spec returns it.

Returns

A frame with one row per field, in the output column’s order. No two rows hold the same values apart from field, so a filter on the other columns reaches each field alone. Its columns:

field

The name, as it appears in the output column.

kind

What it is: pred, resid, sigma, weight_sum, coef, penalty_selected, selected, a statistic’s stem, and so on.

target

The target the field is about, or null.

instance

The instance the field belongs to, by its suffix, as coef(), gram() and closed_groups() name it: "@h500", or "" for a single instance. Null on a field that chooses across the instances (emit_selected, emit_averaged) and on the clocks, which are the spec’s own.

half_life, lam

The decay of the instance the field belongs to, filled for a single instance as for a grid. half_life is the instance’s half-life in clock units, in seconds under a duration (300.0 for "5m"), inf for an infinite one, and null under lam. lam is the spec’s lam, and null under a half-life.

ridge, feature_set, penalty

The grid point: the ridge value, the feature set’s name and the lasso penalty, each null where the spec has no such grid.

quantile

The level of a resid_quantiles or mahal_quantiles field.

lag

The lag, in learned rows, of an ew_cov lag_corr field.

component

The principal component of an ew_cov pc<j>_* field.

state

The hidden state an hmm posterior is about (filtered_state<s>, predicted_state<s>).

class

The class an ew_class posterior is about (p_<class>).

columns

The columns the field is computed from:

  • one for an ew_cov mean, variance or standard deviation, for a feature-health field, and for bocpd’s predictive mean of a column (pred_<column>);

  • the pair for a correlation or a covariance, ordered for lag_corr;

  • every feature for mahal, the principal components and the other fields of kmeans, micro, ew_class, hmm, bocpd and corrchange;

  • a block or a pair of blocks for deco.

Null where no column set describes the field, as for a prediction.

dtype

The type the bank declares to Polars before the first row is read: f64, bool, list[f64], enum (an Enum of its values in their order: withheld_reason’s, an ew_class spec’s classes for class, a grid’s slots for selected_<t>), i64 (every integer: a count, a state, a row index, an id or a cluster label), or clock (scored_clock and learned_clock, in the clock column’s own type).

Raises

ValueError

spec is not a valid spec, as for output_fields().

Examples

This code reads df from Example data:

grid = po.spec.ewridge(
    "m", targets=["y"], features=["x0", "x1"], half_life=[100.0, 500.0], ridge=[1e-6, 0.5]
)
out = po.ModelBank([grid]).fit_predict(df)    # a half-life grid by a ridge grid
idx = po.spec.output_index(grid)
name = idx.filter(
    (pl.col("kind") == "pred")
    & (pl.col("target") == "y")
    & (pl.col("ridge") == 0.5)
    & (pl.col("half_life") == 500.0)
)["field"].item()
print(name, out["m"].struct.field(name).count())
pred_y__r0.5@h500 396

See also

Notes

Every name follows one grammar, which is stable. Read left to right, a name is the kind (pred, abs_resid, lag_corr), then its qualifier, then the target or the columns it is about, then the grid point after __ and the instance after @. A qualifier is a number glued to the letter that says what it is: q a quantile level, l a lag (abs_resid_q0.05_y, mahal_q0.99, lag_corr_l1_x0_x1). The grid point uses letters too, r a ridge and p a lasso penalty, and the instance h, a half-life. A thing the spec has several of is numbered where it is named, glued to its word: pc0_var, filtered_state0, pc0_loading_x1.

The table is made by the Rust code that writes the names, so it cannot drift from them.