polars_online.ModelBank.drop_groups

ModelBank.drop_groups(keys: str | Iterable[str | None], spec: str | int | None = None) → int[source]

Remove the models of these groups, in every spec or in one.

Use it to free the memory a long-running bank holds for groups that have gone quiet, which groups() finds. To have the bank end a group’s model itself, as its rows end, set the spec’s group_close.

Parameters

keys

The group keys to drop, as groups() writes them in its group column: strings, with None for the null group. A list of keys, or one key as a string, as Polars reads one column name where it takes a list of them. A key the bank does not hold drops nothing, and is not an error.

spec

A spec’s name or position, which drops the groups from that spec alone. None, the default, drops them from every spec.

Returns

int: the number of models dropped, one for each spec and group. A dropped group that appears again starts with nothing learned, as a group the bank has never seen does. Nothing else in the bank changes, and rows_fed still counts the dropped groups’ rows.

Raises

TypeError

A key is neither a string nor None.

KeyError

spec is a name the bank does not hold.

IndexError

spec is a position the bank does not hold.

Examples

This code reads df from Example data:

spec = po.spec.ewridge(
    "ridge", targets=["y"], features=["x0"], group="stock_id", half_life=50.0
)
bank = po.ModelBank([spec])
bank.fit_predict(df)
print(bank.drop_groups(["b0", "b9"]))   # b9 was never seen, so one model is dropped
1

See also

  • groups(), which lists the groups and their last clock values.