polars_online.predict

polars_online.predict(frame: pl.LazyFrame, bank: ModelBank | State, *, chunk_size: int | None = None, threads: int | None = None) → pl.LazyFrame[source]
polars_online.predict(frame: pl.DataFrame, bank: ModelBank | State, *, chunk_size: int | None = None, threads: int | None = None) → pl.DataFrame

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

It is frame.online.predict(bank) as a plain function, so that a type checker can see it: the online namespaces are attached when the package is imported, which a type checker does not follow.

Parameters

frame

A query, which gives a query (predict()), or a frame, which gives a frame (predict()).

bank

A ModelBank, or the path of a saved state.

chunk_size

How many rows are predicted at a time, from a query or a frame alike.

threads

How many threads to predict on, as the namespace method takes it.

Returns

A query for a query, and a frame for a frame, with one output column added per spec.

Raises

TypeError

frame is neither a query nor a frame.

Otherwise, what the namespace method raises.

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)
scored = po.predict(today, bank)     # a DataFrame to a type checker too
print(scored["ridge"].struct.field("pred_y").count())
400

See also