polars_online.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 itssolve_failurescolumn.Parameters
specThe spec to read, by name or by position. The default,
None, reads every spec.groupThe group to read: one group key, as
groups()reports it, or a list of keys, withNonein the list for the null group. The default,None, reads every group. A key the bank has never seen gives no rows.
Returns
A
DataFramewithspec,group(asgroups()reports it) andsolve_failures, anInt64, in spec order, then ingroups()’ order. What each model counts:ewridge,huber,quantileA solve that needed jitter, or failed at every jitter and kept the previous fit, the standardized solve included.
huberandquantilealso 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.
marginalEach target whose bins’ refit of their first rows took all 200 of its passes, under
bin_refit_rows.lassoA coordinate descent that ran out of
max_itersweeps before every coefficient moved less thantol, one per target and path point. Not counted: one whose Gram has too few effective rows (Kish’s size) for its features to settle inmax_itersweeps even if they were independent. A sweep shrinks the error by about1 - 2 * lmin,lminthe smallest eigenvalue of the correlation matrix, with the ridge share of the penalty added, so settling totoltakes aboutln(1/tol) / (2 * lmin)sweeps.nindependent rows ofkfeatures give at bestlmin = (1 - sqrt(k / dof)) ** 2,dofbeingn, less one with an intercept. Belowln(1/tol) / (2 * max_iter)that says nothing about the data, and the fit is where the descent stopped. At 100 sweeps and the defaulttolthat 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 forlamthe decay a row), which no more rows would lift: the stream is then never out of its warm-up. Amax_iterbelowln(1/tol) / 2, about 12, is never excused: no number of rows would settle it.kmeansEach run of a
"lloyd"start that was still moving rows after 300 passes, and stopped there.ew_classA row on which a class covariance could not be factorized.
hmmA 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.bocpdA 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:
rlskeeps a Cholesky factor andkalmana covariance, and the gradient models keep no second moment to factorize.Raises
KeyErrorspecis a name the bank does not have.IndexErrorspecis a position the bank does not have.TypeErrorgroupis not a str, a list of them withNoneallowed, orNone.
Examples
This code reads
dffrom Example data:spec = po.spec.ewridge("ridge", targets=["y"], features=["x0", "x1"], half_life=100.0) bank = po.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(), whosesolve_failuresfinding 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%.