FBetaScore¶
yohou.metrics.classification.FBetaScore
¶
Bases: BaseHardLabelScorer
F-beta score from class-probability forecasts.
Computes the weighted harmonic mean of precision and recall. With
beta=1.0 this is the standard F1 score.
\[F_\beta = \frac{(1+\beta^2) \cdot TP}{(1+\beta^2) \cdot TP + \beta^2 \cdot FN + FP}\]
Parameters¶
| Name | Type | Description | Default |
|---|---|---|---|
beta
|
float
|
Weight of recall relative to precision. |
1.0
|
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 F-beta is better). |
Examples¶
>>> import polars as pl
>>> from datetime import datetime
>>> from yohou.metrics.classification import FBetaScore
>>> 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 = FBetaScore(beta=1.0)
>>> _ = scorer.fit(y_true)
>>> scorer.score(y_true, y_pred)
0.777...
See Also¶
Source Code¶
Show/Hide source
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 | |