我是 GluonTS 的新手,我正在尝试了解这个概念是如何工作的。 在文档网站上的“将数据集拆分为训练和测试”部分下
他们定义了一种分割训练数据和测试数据的机制,如下所示:
training_dataset, test_template = split(
dataset, date=pd.Period("2015-04-07 00:00:00", freq="1H")
)
test_pairs = test_template.generate_instances(
prediction_length=prediction_length,
windows=3,
distance=24,
)
training_dataset可以直接使用,如下:
predictor = estimator.train(training_dataset)
这个test_pairs的类型是gluonts.dataset.split.TestData
但是当使用 test_pairs 作为预测的输入时:
forecast_it, ts_it = make_evaluation_predictions(
dataset=test_pairs, predictor=predictor,
num_samples=100,
)
ts_it 的类型将是一个“map”,当将其转换为列表时,它将返回一个空列表。
有谁知道如何使用 test_pairs 来实际进行预测和评估结果?
我必须为其编写自定义代码
df = pd.read_parquet("inbounds.parquet")
df.head(3)
ds = PandasDataset(df, target="containers")
freq = "D"
split_date = "2023-03-31"
windows = 10
distance = 1
ds_train, test_template = split(
ds, date=pd.Period(split_date, freq=freq)
)
ds_test_windows = test_template.generate_instances(
prediction_length=prediction_length,
windows=windows,
distance=distance,
)
def windows_to_ds_test(ds_test_windows: TestData) -> ListDataset:
windows = list(ds_test_windows)
ds_test = [{
"start": w[0]["start"],
"target": np.concatenate((w[0]["target"], w[1]["target"]))
} for w in windows]
return ListDataset(ds_test, freq=freq)
ds_test = windows_to_ds_test(ds_test_windows)
forecast_it, ts_it = make_evaluation_predictions(
dataset=ds_test,
predictor=predictor,
)