multitask.base.agg_predictor(results, targets, weights)
Aggregate per-target prediction packages into a weighted forecast.
Combines future predictions, training predictions, and training actuals from per-target prediction packages into an aggregated package compatible with downstream consumers. This is a module-level convenience function; the same logic is available as BaseTask.agg_predictor.
Parameters
results
Dict [str , Dict [str , Any ]]
Mapping of target name to prediction package (as returned by build_prediction_package).
required
targets
List [str ]
Ordered list of target names to aggregate.
required
weights
List [float ]
Per-target aggregation weights aligned with targets.
required
Returns
Dict [str , Any ]
Aggregated prediction package with keys train_actual,
Dict [str , Any ]
train_pred, future_pred, future_actual,
Dict [str , Any ]
metrics_train, metrics_future, metrics_future_one_day,
Dict [str , Any ]
validation_passed, and (when present in all sources)
Dict [str , Any ]
test_actual.
Examples
import numpy as np
import pandas as pd
from spotforecast2_safe.multitask.base import agg_predictor
rng = np.random.default_rng(0 )
idx_train = pd.date_range("2023-01-01" , periods= 100 , freq= "h" , tz= "UTC" )
idx_future = pd.date_range("2023-01-05 04:00" , periods= 6 , freq= "h" , tz= "UTC" )
def _pkg(train_val, future_val):
return {
"train_actual" : pd.Series(np.full(100 , train_val), index= idx_train),
"train_pred" : pd.Series(np.full(100 , train_val * 0.99 ), index= idx_train),
"future_pred" : pd.Series(np.full(6 , future_val), index= idx_future),
"future_actual" : pd.Series(dtype= "float64" ),
}
results = {"wind" : _pkg(100.0 , 110.0 ), "solar" : _pkg(200.0 , 210.0 )}
agg = agg_predictor(results, targets= ["wind" , "solar" ], weights= [0.5 , 0.5 ])
print (f"future_pred (weighted mean): { agg['future_pred' ]. iloc[0 ]:.1f} " )
assert set (agg.keys()) >= {"train_actual" , "train_pred" , "future_pred" , "validation_passed" }
future_pred (weighted mean): 160.0