polars_online.ModelBank.predict_arrow

ModelBank.predict_arrow(df: DataFrame) → list[ArrowStruct][source]

Predict a frame’s rows without learning, and return each spec’s output as an Arrow array.

Use it to serve a bank’s predictions to a library other than Polars. It is to predict() what fit_predict_arrow() is to fit_predict(): the same predictions, the same values, and the bank left exactly as it was.

Warning

The Arrow output (fit_predict_arrow(), this method and ArrowStruct) is unstable: it may change in any release without that counting as a breaking change. Under POLARS_ONLINE_WARN_UNSTABLE=1, each call issues UnstableWarning.

Parameters

df

The rows to predict, as a Polars DataFrame, as predict() takes it.

Returns

A list of ArrowStruct, one per spec, as fit_predict_arrow() returns, each readable once.

Raises

What predict() raises for the same frame.

UnstableWarning

A warning, not an error: issued by each call under POLARS_ONLINE_WARN_UNSTABLE=1.

Examples

This code reads df from Example data:

spec = po.spec.ewridge("ridge", targets=["y"], features=["x0", "x1"], half_life=100.0)
bank = po.ModelBank([spec])
bank.fit_predict(df.head(300))
structs = bank.predict_arrow(df.tail(100))      # the bank is not changed
served = df.tail(100).with_columns([pl.Series(s) for s in structs])
print(served["ridge"].struct.field("pred_y").count(), bank.rows_fed)
100 300

See also