DataFrame.rheon.fit_predict¶
- DataFrameRheonNamespace.fit_predict(specs: Iterable[dict[str, Any]] | None = None, *, load_state: str | PathLike[str] | ModelBank | None = None, save_state: str | PathLike[str] | None = None, closed_groups: str | PathLike[str] | None = None, chunk_size: int | None = None, threads: int | None = None) DataFrame[source]¶
Add each spec’s output column to a frame’s rows, learning them, in one call.
It is
ModelBank(specs).fit_predict(df)in one call, from a bank that is then dropped. Use it for a frame already in memory, when you do not need the bank afterwards. To feed the same bank more rows later, keep aModelBankof your own, and for a query, uself.rheon.fit_predict.Parameters
specsThe specs of a bank that starts with nothing learned. Leave it out to start from
load_state.load_stateWhat to start from in place of the specs: the path of a saved state, or a
ModelBank, which is copied and does not move.save_stateThe path to save the bank to before it is dropped (
save()).closed_groupsThe path of a file to write the groups that closed to, in the format its extension names, before
save_stateis written (closed_groups()). A CSV holds each list column as JSON text, aslf.rheon.fit_predictwrites it. A file that cannot be written still leaves the state saved before its error is raised.chunk_sizeHow many rows the bank learns at a time, as
lf.rheon.fit_predictreads its input.None, the default, feeds the frame as one chunk. The numbers are the same either way: only the rowscoefis written on move, to each chunk’s last row of each group.threadsHow many threads the bank runs on, as
LazyFrameRheonNamespace.fit_predict()takes it.
Returns
The frame with one output column added per spec, as
fit_predict()returns it.Raises
What
ModelBank,fit_predict(),load()andsave()raise, and:ValueErrorNeither
specsnorload_stateis given,chunk_sizeis below 1, orclosed_groupsis a file thatLazyFrameRheonNamespace.fit_predict()refuses, checked before the fit.FileNotFoundErrorThe directory of
save_stateorclosed_groupsis not there, checked before the fit rather than after it.
Examples
This code reads
dffrom Example data:spec = rp.spec.ewridge("ridge", targets=["y"], features=["x0", "x1"], half_life=100.0) out = df.rheon.fit_predict([spec], save_state="ridge.state") print(out["ridge"].struct.field("pred_y").count(), "of", out.height, "rows predicted")
396 of 400 rows predicted
See also
LazyFrameRheonNamespace.fit_predict(), the same over a query, run as the query runs.fit_predict(), the same with a bank you keep.rheon.polars.fit_predict(), this method as a function a type checker can see.