polars_online.spec.coef_index¶
- polars_online.spec.coef_index(spec: dict[str, Any]) DataFrame[source]¶
List the layout of a spec’s
coeflists, one row per position.Use it to find which position of a
coeflist holds a coefficient. Every instance’s list has this layout.coef_fields()is the same table for each instance, with the field each list sits in and the column each entry unnests to.Parameters
specA spec, as a builder of
polars_online.specreturns it.
Returns
A frame with one row per position.
coefis flat: for each target and grid point in turn, its terms in order. The frame mapspositiontotarget, the grid point’sridge,feature_setandpenalty, andterm:"intercept", a feature name, or"level"or"trend"forholt().For
kmeans()the entries are the centers, soclusterreads0,1, and so on, andtermis the feature whose coordinate the position holds.For
hmm()an entry is a state, instate, and forew_class()a class, inclass.For
deco()an entry isrho, or a block or a pair of blocks, intarget, andtermreads"rho".
It is empty, with the same columns, for a spec with no fixed layout to index, as
coef_fields()is:ew_cov, which has no coefficients;seqtest, which reports evidence;micro, whosecoefhas as many entries as there are established summaries;marginal,rcov,corrchange,bocpdandaudit, which report none.
Raises
ValueErrorspecis not a valid spec, as foroutput_fields().
Examples
This code reads
dffrom 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 ci = po.spec.coef_index(grid) pos = ci.filter( (pl.col("target") == "y") & (pl.col("ridge") == 0.5) & (pl.col("term") == "x1") )["position"].item() slope = out["m"].struct.field("coef@h100").list.get(pos) print(ci.height, pos)
6 5
See also
coef_fields(), the same for each instance, with each entry’s column name.output_index(), every field with the values its name encodes.