DataFrame.online.predict

DataFrameOnlineNamespace.predict(bank: ModelBank | str | PathLike[str], *, chunk_size: int | None = None, threads: int | None = None) → DataFrame[source]

Predict a frame’s rows from a bank as it stands, learning nothing.

It is predict() over the frame, from a bank or a saved state. Use it to serve rows in memory from a bank that has learned. For a query, use lf.online.predict.

Parameters

bank

The bank to predict from: a ModelBank, which does not move, or the path of a saved state.

chunk_size

How many rows are predicted at a time, as lf.online.predict reads its input. None, the default, predicts the frame as one chunk. The numbers are the same either way. coef is written on each group’s last row in each chunk that is not skipped, whatever coef_every and max_rows_between_coefs say.

threads

How many threads to predict on, as LazyFrameOnlineNamespace.predict() takes it.

Returns

The frame with one output column added per spec, as predict() returns it.

Raises

What load() (for a path) and predict() raise, and:

TypeError

bank is neither a bank nor a path, or chunk_size is not a whole number, as WrongTypeError, which is a ValueError too.

ValueError

chunk_size is below 1.

Examples

This code reads df and today from Example data:

spec = po.spec.ewridge("ridge", targets=["y"], features=["x0", "x1"], half_life=100.0)
bank = po.ModelBank([spec])
bank.fit(df)                                  # learn df's 400 rows
scored = today.online.predict(bank)           # the next 400, unlearned
print(scored["ridge"].struct.field("pred_y").count(), bank.rows_fed)
400 400

See also