rheon.polars.ModelBank.solve_failures

ModelBank.solve_failures(spec: str | int | None = None, group: str | Iterable[str | None] | None = None) → DataFrame[source]

Return how many of each model’s solves needed help, one row per spec and group.

Use it to find the models whose inputs are degenerate (constant or collinear features, or far too few rows for the number of features), or whose refit or seeding stopped at its pass cap. A count above 0 means a solve needed help, not that anything crashed. For every count of a model at once, use summary(), which carries this one as its solve_failures column.

Parameters

spec

The spec to read, by name or by position. The default, None, reads every spec.

group

The group to read: one group key, as groups() reports it, or a list of keys, with None in the list for the null group. The default, None, reads every group. A key the bank has never seen gives no rows.

Returns

A DataFrame with spec, group (as groups() reports it) and solve_failures, an Int64, in spec order, then in groups()’ order. What each model counts:

ewridge, huber, quantile

A solve that needed jitter, or failed at every jitter and kept the previous fit, the standardized solve included. huber and quantile also count each target whose refit of its first rows took all 200 of its passes, where the fit of the last pass stands.

sgd(loss="huber")

Each target whose refit of its first rows took all 200 of its passes.

marginal

Each target whose bins’ refit of their first rows took all 200 of its passes, under bin_refit_rows.

lasso

A coordinate descent that ran out of max_iter sweeps before every coefficient moved less than tol, one per target and path point. Not counted: one whose Gram has too few effective rows (Kish’s size) for its features to settle in max_iter sweeps even if they were independent. A sweep shrinks the error by about 1 - 2 * lmin, lmin the smallest eigenvalue of the correlation matrix, with the ridge share of the penalty added, so settling to tol takes about ln(1/tol) / (2 * lmin) sweeps. n independent rows of k features give at best lmin = (1 - sqrt(k / dof)) ** 2, dof being n, less one with an intercept. Below ln(1/tol) / (2 * max_iter) that says nothing about the data, and the fit is where the descent stopped. At 100 sweeps and the default tol that is under about 2.3 rows a feature, at 1,000 sweeps 1.25. Past it every cap hit counts, so nearly dependent features show here. So does every cap hit under a decay whose Kish size stays below that bound (about (1 + lam) / (1 - lam) rows for lam the decay a row), or under a window_size once rows have aged out of a window that holds fewer than that bound, which no more rows would lift: the stream is then never out of its warm-up. A max_iter below ln(1/tol) / 2, about 12, is never excused: no number of rows would settle it.

kmeans

Each run of a "lloyd" start that was still moving rows after 300 passes, and stopped there.

ew_class

A row on which a class covariance could not be factorized.

hmm

A row whose state densities could not be evaluated, where the filter is left where it stands, and, as for kmeans, each run of a "lloyd" start of its seeding that was still moving rows after 300 passes.

bocpd

A row whose predictive density could not be evaluated. It reports nulls and leaves the run-length posterior where it stands, and the count makes a run of them visible.

Every other model reports 0 because it counts nothing, not because nothing can fail: rls keeps a Cholesky factor and kalman a covariance, and the gradient models keep no second moment to factorize.

Raises

KeyError

spec is a name the bank does not have.

IndexError

spec is a position the bank does not have.

TypeError

group is not a str, a list of them with None allowed, or None.

Examples

This code reads df from Example data:

spec = rp.spec.ewridge("ridge", targets=["y"], features=["x0", "x1"], half_life=100.0)
bank = rp.ModelBank([spec])
bank.fit(df)
print(bank.solve_failures().rows())                 # no solve needed help
[('ridge', '', 0)]

To find the models that need a look, keep the rows above 0: bank.solve_failures().filter(pl.col("solve_failures") > 0).

See also

  • summary(), which carries this count beside the rest.

  • check(), whose solve_failures finding reads it.

  • coef(), the fits the solves gave.

Notes

A solve never returns NaN silently. A near-singular system is tried again with a larger diagonal jitter at each try, and a solve that fails at every jitter keeps the previous coefficients. Both are counted here.

Past about 20% of outliers on one side, a Huber refit converges slowly. Over 3,000 simulated targets of 50 to 500 rows, with up to 45% of the rows on one side moved by a level, 50 passes ran out on 149 of them, and 200 passes on 9, all nine past 39%.