Measuring a threshold¶
rainfall_thresholds.measure ¶
How good a threshold is: landslides caught, and the alerts it costs.
A threshold is only half an answer. T5 catches 95 % of past landslides by construction; what it does not say is how often it is exceeded when nothing happens. These functions measure both sides on the same scale, for any score that grows with danger: the exceedance of a threshold in decades, a 24-hour total in mm, a probability.
You bring two lists of scores:
landslides: one score per landslide, the highest in the hours before it (the lead window is your choice: 24, 48, 72 hours);ordinary: one score per unit of time and place you could alert on (cell-hours, municipality-days...), with or without landslides, as your alert budget is counted.
None is a score that was not measured. It is left out and counted,
never read as zero.
Definitions, as in Limen's backtests (limen#243, limen#352):
- a landslide is caught when its score reaches the cutoff (
>=); - the alert share is the share of ordinary units at or above the cutoff;
- discrimination is hit rate over alert share: 1 is chance;
- the cutoff at a budget is the score that puts that share of ordinary units on alert. Ties can make the share a little higher than asked.
Skill
dataclass
¶
What a cutoff catches, and what it costs.
alert_share
property
¶
alert_share: float | None
Share of the ordinary units on alert; None without units.
discrimination
property
¶
discrimination: float | None
Hit rate over alert share: 1 is chance. None when either is unknown or zero.
alerts_per_caught
property
¶
alerts_per_caught: float | None
Alerts paid for every landslide caught; None when none is caught.
skill ¶
skill(landslides: Iterable[float | None], ordinary: Iterable[float | None], cutoff: float) -> Skill
Landslides caught and ordinary units on alert at cutoff.
cutoff_at_budget ¶
cutoff_at_budget(ordinary: Iterable[float | None], budget: float, *, floor: float | None = None) -> float
The cutoff that puts budget (0-1) of the ordinary units on alert.
It is the k-th highest score, k = max(1, round(budget * n)). With
floor, a score at or below it never alerts (for a score that is 0 when
nothing happens, floor=0): the cutoff is then at least the lowest score
above it, or inf when there is none. Without measured scores, inf.
skill_at_budget ¶
skill_at_budget(landslides: Iterable[float | None], ordinary: Iterable[float | None], budget: float, *, floor: float | None = None) -> Skill
:func:skill at the cutoff of :func:cutoff_at_budget.
The fair way to compare two scores: at the same share of units on alert, which catches more landslides? Counting at a fixed level instead rewards the score that alerts more.
auc ¶
auc(landslides: Iterable[float | None], ordinary: Iterable[float | None]) -> float | None
The chance that a landslide scores higher than an ordinary unit (Mann-Whitney).
Ties count half. None without one of the two lists. Read it with
care when many scores are tied, for example at zero: it then measures the
order of the few that are not, and says nothing about the level.