kashif's picture
kashif HF staff
Upload 10 files
45e60de
raw
history blame contribute delete
751 Bytes
from typing import List
from gluonts.dataset.split import split
from gluonts.dataset.common import Dataset
from gluonts.model.forecast import Forecast
from gluonts.evaluation.backtest import _to_dataframe, Evaluator
def score_predictions(
dataset: Dataset,
predictions: List[Forecast],
prediction_length: int,
seasonality: int,
):
_, test_template = split(dataset, offset=-prediction_length)
test_data = test_template.generate_instances(prediction_length)
ts_iterator = map(_to_dataframe, test_data)
evaluator = Evaluator(
quantiles=[0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9], seasonality=seasonality
)
metrics, _ = evaluator(ts_iterator=ts_iterator, fcst_iterator=predictions)
return metrics