Precision¶
yohou.metrics.classification.Precision
¶
Bases: BaseHardLabelScorer
Precision from class-probability forecasts.
Computes precision (positive predictive value) by argmaxing predicted probabilities into hard labels and computing the ratio of true positives to all predicted positives.
\[\text{Precision}_k = \frac{TP_k}{TP_k + FP_k}\]
Parameters¶
| Name | Type | Description | Default |
|---|---|---|---|
average
|
str
|
Class averaging strategy: |
"macro"
|
zero_division
|
float
|
Value returned when the denominator is zero. |
0.0
|
aggregation_method
|
list of str or str
|
Dimensions to aggregate over. |
"all"
|
groups
|
list of str, dict of str to float, or None
|
Panel group filter or filter with weights. |
None
|
components
|
list of str, dict of str to float, or None
|
Component filter or filter with weights. |
None
|
Attributes¶
| Name | Type | Description |
|---|---|---|
lower_is_better |
bool
|
Always False (higher precision is better). |
Examples¶
>>> import polars as pl
>>> from datetime import datetime
>>> from yohou.metrics.classification import Precision
>>> y_true = pl.DataFrame({
... "time": [datetime(2020, 1, i) for i in range(1, 6)],
... "weather": ["sunny", "rainy", "cloudy", "sunny", "rainy"],
... })
>>> y_pred = pl.DataFrame({
... "vintage_time": [datetime(2019, 12, 31)] * 5,
... "time": [datetime(2020, 1, i) for i in range(1, 6)],
... "weather_proba_sunny": [0.7, 0.1, 0.2, 0.2, 0.1],
... "weather_proba_rainy": [0.2, 0.8, 0.1, 0.1, 0.8],
... "weather_proba_cloudy": [0.1, 0.1, 0.7, 0.7, 0.1],
... })
>>> scorer = Precision()
>>> _ = scorer.fit(y_true)
>>> scorer.score(y_true, y_pred)
0.833...
See Also¶
Recall: Recall (sensitivity).FBetaScore: Weighted harmonic mean of precision and recall.