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’sgroup_close.Parameters
keysThe group keys to drop, as
groups()writes them in itsgroupcolumn: strings, withNonefor 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.specA 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, androws_fedstill counts the dropped groups’ rows.Raises
TypeErrorA key is neither a string nor
None.KeyErrorspecis a name the bank does not hold.IndexErrorspecis a position the bank does not hold.
Examples
This code reads
dffrom 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.