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 a ModelBank of your own, and for a query, use lf.rheon.fit_predict.

Parameters

specs

The specs of a bank that starts with nothing learned. Leave it out to start from load_state.

load_state

What 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_state

The path to save the bank to before it is dropped (save()).

closed_groups

The path of a file to write the groups that closed to, in the format its extension names, before save_state is written (closed_groups()). A CSV holds each list column as JSON text, as lf.rheon.fit_predict writes it. A file that cannot be written still leaves the state saved before its error is raised.

chunk_size

How many rows the bank learns at a time, as lf.rheon.fit_predict reads its input. None, the default, feeds the frame as one chunk. The numbers are the same either way: only the rows coef is written on move, to each chunk’s last row of each group.

threads

How 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() and save() raise, and:

ValueError

Neither specs nor load_state is given, chunk_size is below 1, or closed_groups is a file that LazyFrameRheonNamespace.fit_predict() refuses, checked before the fit.

FileNotFoundError

The directory of save_state or closed_groups is not there, checked before the fit rather than after it.

Examples

This code reads df from 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