Rule Monitoring#
Functions#
compare_rule_metrics#
- iguanas.rule_monitoring.compare_rule_metrics(ref_metrics: polars.DataFrame, curr_metrics: polars.DataFrame, thresholds: dict[str, float] | None = None) polars.DataFrame[source]#
Compare rule metrics between a reference period and a current period.
Takes two
compute_metrics()outputs and returns the per-rule delta for every shared metric column, together with a boolean flag indicating whether the rule has degraded beyond an optional threshold.- Parameters:
ref_metrics (pl.DataFrame) – Baseline metrics from
compute_metrics(). Must contain arulecolumn.curr_metrics (pl.DataFrame) – Current-period metrics from
compute_metrics(). Must contain arulecolumn. Only rules present in both DataFrames are compared (inner join onrule).thresholds (dict[str, float] | None, default=None) – Maximum allowed drop per metric, e.g.
{"precision": 0.05}flags rules whose precision fell by more than 5 pp. WhenNone, any negative delta is flagged.
- Returns:
One row per rule with columns:
rule{metric}_ref— metric value in the reference period{metric}_curr— metric value in the current period{metric}_delta—curr - ref(negative means degradation){metric}_degraded—Truewhen the drop exceeds the threshold
- Return type:
pl.DataFrame
Examples
>>> import polars as pl >>> from iguanas.metrics import compute_metrics >>> from iguanas.rule_monitoring import compare_rule_metrics >>> R_ref = pl.DataFrame({"rule_A": [True, False, True]}) >>> y_ref = pl.Series([True, True, True]) >>> R_curr = pl.DataFrame({"rule_A": [True, False, False]}) >>> y_curr = pl.Series([True, True, True]) >>> ref = compute_metrics(R_ref, y_ref) >>> curr = compute_metrics(R_curr, y_curr) >>> compare_rule_metrics(ref, curr, thresholds={"precision": 0.1})