rheon.spec.coef_fields¶
- rheon.spec.coef_fields(spec: dict[str, Any]) _Frame[source]¶
List every coefficient a spec reports, with its place in
coefand its unnested column.Use it to reach one coefficient in the nested output without writing its field’s name or its position by hand, or to read the column names
unnest()gives. For onecoeflist’s layout alone, usecoef_index().Parameters
specA spec, as a builder of
rheon.specreturns it.
Returns
A frame with one row per instance, target, grid point and term. It is empty, with the same columns, for the kinds that report no coefficients (
ew_cov,seqtest,marginal,rcov,corrchange,bocpdandaudit), and formicro, whosecoefhas no fixed layout. Its columns:fieldThe
coeflist the coefficient sits in:coef, orcoef@h500for each half-life’s instance.positionIts index in that list.
nameThe column
unnest()gives it:coef_{target}_{term}{combo}{instance}, socoef_y_x1__r0.5@h500sits besidepred_y__r0.5@h500. Thecoef_prefix and the target are there because a barex1would collide with the feature column of that name in the same frame.deco()’s arecoef_{entry}{instance}, its entryrhoor a block or pair of blocks (coef_tech,coef_tech_banks).target,instance,half_life,lam,ridge,feature_set,penaltyAs
output_index()reports them.targetisew_class()’s label column, adeco()entry, and null for akmeans()center and anhmm()state, which belong to no target.cluster,state,classThe
kmeans()center, thehmm()state or theew_class()class whose coordinates the entry holds, and null for every other kind.term"intercept", a feature name,"level"or"trend"forholt(), or"rho"fordeco().
Raises
ValueErrorspecis not a valid spec, as foroutput_fields().
Examples
This code reads
dffrom Example data:grid = rp.spec.ewridge( "m", targets=["y"], features=["x0", "x1"], half_life=[100.0, 500.0], ridge=[1e-6, 0.5] ) out = rp.ModelBank([grid]).fit_predict(df) # a half-life grid by a ridge grid cf = rp.spec.coef_fields(grid) row = cf.filter( (pl.col("target") == "y") & (pl.col("term") == "x1") & (pl.col("ridge") == 0.5) & (pl.col("half_life") == 500.0) ).row(0, named=True) slope = out["m"].struct.field(row["field"]).list.get(row["position"]) print(row["field"], row["position"], row["name"])
coef@h500 5 coef_y_x1__r0.5@h500
See also
coef_index(), onecoeflist’s layout.output_index(), every field with the values its name encodes.unnest(), which writes these columns.
Notes
The table is made by the Rust code that names the fields, from the order the models lay the list out in. That order is the intercept first when the spec has one, then every feature, each target and grid point in turn, in the order the
predfields are declared. A feature outside a feature set reads zero.