MeanSquaredError¶
yohou.metrics.point.MeanSquaredError
¶
Bases: BasePointScorer
Mean Squared Error metric for point forecasts.
Computes the average of squared differences between predictions and actual values. This metric heavily penalizes large errors, making it sensitive to outliers.
The MSE is defined as:
where \(y_i\) is the actual value, \(\\hat{y}_i\) is the predicted value, and \(n\) is the number of observations.
Parameters¶
| Name | Type | Description | Default |
|---|---|---|---|
aggregation_method
|
list of str or str
|
Dimensions to aggregate over. Options: - "stepwise": Aggregate across forecasting steps. - "vintagewise": Aggregate across vintages (observed times). - "componentwise": Aggregate across components, return per-timestep DataFrame - "groupwise": Aggregate across panel groups (panel data only) - "all": Aggregate across all dimensions (returns scalar). Same as ["stepwise", "vintagewise", "componentwise", "groupwise"]. Example outputs: - ["stepwise", "vintagewise"]: Per-component (and per-group) DataFrame. - "componentwise" or ["componentwise"]: Per-timestep (and per-group) DataFrame. - "groupwise" or ["groupwise"]: Per-component per-timestep DataFrame (panel aggregated). - ["stepwise", "vintagewise", "componentwise"]: Scalar (global) or per-group DataFrame (panel). - "all": Scalar float (hierarchically aggregated for panel data). |
"all"
|
groups
|
list of str, dict of str to float, or None
|
Panel group filter (list) or filter with weights (dict). |
None
|
components
|
list of str, dict of str to float, or None
|
Component filter (list) or filter with weights (dict). |
None
|
Attributes¶
| Name | Type | Description |
|---|---|---|
lower_is_better |
bool
|
Always True for MeanSquaredError. |
Examples¶
>>> import polars as pl
>>> from datetime import datetime
>>> from yohou.metrics import MeanSquaredError
>>> y_true = pl.DataFrame({
... "time": [datetime(2020, 1, 1), datetime(2020, 1, 2), datetime(2020, 1, 3)],
... "value": [10.0, 20.0, 30.0],
... })
>>> y_pred = pl.DataFrame({
... "vintage_time": [datetime(2019, 12, 31)] * 3,
... "time": [datetime(2020, 1, 1), datetime(2020, 1, 2), datetime(2020, 1, 3)],
... "value": [12.0, 19.0, 28.0],
... })
>>> mse = MeanSquaredError()
>>> _ = mse.fit(y_true)
>>> mse.score(y_true, y_pred)
3.0
Notes¶
- Squaring errors penalizes large deviations more than small ones
- More sensitive to outliers compared to MAE
- Units are squared, making direct interpretation less intuitive (use RMSE for original units)
- Commonly used in regression and when large errors are particularly undesirable
See Also¶
MeanAbsoluteError: Mean Absolute Error, less sensitive to outliersRootMeanSquaredError: Root Mean Squared Error, MeanSquaredError in original unitsRootMeanSquaredScaledError: Root Mean Squared Scaled Error, scale-independent version
Source Code¶
Show/Hide source
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 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 | |
Tutorials¶
The following example notebooks use this component:
-
How to Use Point Forecast Metrics
Evaluation-Search
Compare MAE, MAPE, MASE, RMSE, and other point metrics across multiple forecasters with componentwise and groupwise aggregation.
-
Quickstart
Quickstart
Comprehensive end-to-end tour of yohou beyond the Getting Started tutorials, covering data loading, baseline forecasting, preprocessing pipelines, decomposition, cross-validation search, and interval prediction.