Entity-level evaluation¶
This section documents evaluation utilities for computing metrics and diagnostics at the individual entity level.
Entity-level evaluation supports analysis of forecast performance and readiness for a single unit (e.g. store, item, or asset) over time.
eb_evaluation.dataframe.entity
¶
Entity-level evaluation utilities (DataFrame helpers).
This module contains DataFrame-oriented evaluation helpers that operate on panel data: entity-by-interval observations containing actuals and forecasts.
The primary helper evaluates each entity using entity-specific cost asymmetry parameters (cost ratios) that are typically estimated upstream (for example, via a balance-based estimator). The result is one row per entity containing cost-weighted and service-oriented Electric Barometer metrics, plus familiar symmetric error metrics.
evaluate_panel_with_entity_R(df, entity_R, *, entity_col='entity', y_true_col='actual_qty', y_pred_col='forecast_qty', R_col='R', co_col='co', tau=2.0, sample_weight_col=None)
¶
Evaluate an entity-interval panel using entity-level cost ratios.
This helper evaluates each entity slice of a panel using entity-specific cost asymmetry parameters. It is designed to pair naturally with a table that provides, for each entity, a cost ratio:
and an overbuild cost coefficient \(c_o\). For each entity \(e\), the implied shortfall (underbuild) cost coefficient is:
Evaluation flow
For each entity:
- Join the entity-level values \((R_e, c_o)\) onto all intervals for that entity.
- Construct per-row arrays \(c_u\) and \(c_o\) that are constant within the entity slice.
- Compute the EB metric suite (CWSL, NSL, UD, HR@\(\tau\), FRS) using the entity-specific cost parameters, plus common symmetric metrics.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
Panel of interval-level data containing at least:
If |
required |
entity_R
|
DataFrame
|
Table with one row per entity containing at least:
Typically produced by an upstream calibration step (for example, an entity ratio estimator). |
required |
entity_col
|
str
|
Column identifying the entity (for example, |
"entity"
|
y_true_col
|
str
|
Column containing realized demand / actual values. |
"actual_qty"
|
y_pred_col
|
str
|
Column containing baseline forecast values. |
"forecast_qty"
|
R_col
|
str
|
Column in |
"R"
|
co_col
|
str
|
Column in |
"co"
|
tau
|
float
|
Absolute-error tolerance parameter for the hit-rate metric HR@\(\tau\). |
2.0
|
sample_weight_col
|
str | None
|
Optional column in |
None
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
One row per entity with columns:
If a metric is undefined for a given entity slice (for example, due to a metric-specific validation failure), that metric value is returned as NaN for that entity. |
Raises:
| Type | Description |
|---|---|
KeyError
|
If required columns are missing from |
ValueError
|
If the merge between |
Notes
- The join uses an inner merge on
entity_col. Entities present indfbut missing fromentity_Rare dropped. This is intentional: evaluation requires cost parameters. - Cost arrays are constructed per entity as constants, enabling vectorized evaluation calls.
- Some metrics in :mod:
eb_metrics.metricsmay not accept sample weights; this function calls those metrics unweighted to match their signatures.