Skip to content

Commit c2b05d0

Browse files
committed
return the highest threshold in the event of a tie (we want to be more generous)
1 parent 2c89cdc commit c2b05d0

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

python/rapidstats/_metrics.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ def bad_rate_at_thresholds(
323323
of bad. If the target bad rate is not specified, return a Polars DataFrame of the
324324
model approved bad rate at each value of `y_score`. In the event that multiple
325325
thresholds satisfy the target bad rate, (unlikely outside of random data),
326-
the lowest threshold is chosen.
326+
the highest threshold is chosen (less conservative).
327327
328328
Parameters
329329
----------
@@ -366,7 +366,7 @@ def bad_rate_at_thresholds(
366366
)
367367
.filter(pl.col("diff").eq(pl.col("diff").min()))
368368
.select("threshold", "appr_bad_rate")
369-
.sort("threshold")
369+
.sort("threshold", descending=True)
370370
.collect()
371371
.row(0)
372372
)
@@ -377,12 +377,11 @@ def appr_rate_at_thresholds(
377377
target_appr_rate: Optional[float] = None,
378378
) -> Union[pl.DataFrame, tuple[float, float]]:
379379
"""Finds the threshold that is the closest to achieving the target approval rate,
380-
assuming that `y_score` is the probability of bad.
381-
approved population, assuming that True is bad and that `y_score` is the probability
382-
of bad. If the target bad rate is not specified, return a Polars DataFrame of the
383-
model approved bad rate at each value of `y_score`. In the event that multiple
384-
thresholds satisfy the target bad rate, (unlikely outside of random data),
385-
the lowest threshold is chosen.
380+
assuming that `y_score` is the probability of bad. An approval is defined as
381+
`y_score` < t. If the target approval rate is not specified, return a Polars
382+
DataFrame of the approval rate at each value of `y_score`. In the event that
383+
multiple thresholds satisfy the target approval rate, (unlikely outside of random
384+
data), the highest threshold is chosen (less conservative).
386385
387386
Parameters
388387
----------
@@ -417,7 +416,7 @@ def appr_rate_at_thresholds(
417416
)
418417
.filter(pl.col("diff").eq(pl.col("diff").min()))
419418
.select("threshold", "appr_rate")
420-
.sort("threshold")
419+
.sort("threshold", descending=True)
421420
.collect()
422421
.row(0)
423422
)

0 commit comments

Comments
 (0)