gpt4 book ai didi

python - 由 Gluon-TS 示例生成的预测约为 0

转载 作者:行者123 更新时间:2023-12-01 07:19:03 25 4
gpt4 key购买 nike

我遵循了这个指南:https://aws.amazon.com/blogs/machine-learning/creating-neural-time-series-models-with-gluon-time-series/

并得到以下脚本:

import pandas as pd
import matplotlib.pyplot as plt
from gluonts.dataset.common import ListDataset
from itertools import islice
from gluonts.evaluation.backtest import make_evaluation_predictions
from gluonts.model.deepar import DeepAREstimator
from gluonts.trainer import Trainer

def plot_forecasts(tss, forecasts, past_length, num_plots):
for target, forecast in islice(zip(tss, forecasts), num_plots):
ax = target[-past_length:].plot(figsize=(12, 5), linewidth=2)
forecast.plot(color='g')
plt.grid(which='both')
plt.legend(["observations", "median prediction", "90% confidence interval", "50% confidence interval"])
plt.show()

if __name__ == "__main__":

url = "https://raw.githubusercontent.com/numenta/NAB/master/data/realTweets/Twitter_volume_AMZN.csv"
df = pd.read_csv(url, header=0, index_col=0)

training_data = ListDataset(
[{"start": df.index[0], "target": df.value[:"2015-04-05 00:00:00"]}],
freq = "5min"
)

estimator = DeepAREstimator(freq="5min",
prediction_length=36,
trainer=Trainer(epochs=1))

predictor = estimator.train(training_data=training_data)

test_data = ListDataset(
[
{"start": df.index[0], "target": df.value[:"2015-04-10 03:00:00"]},
{"start": df.index[0], "target": df.value[:"2015-04-15 18:00:00"]},
{"start": df.index[0], "target": df.value[:"2015-04-20 12:00:00"]}
],
freq = "5min"
)

forecast_it, ts_it = make_evaluation_predictions(test_data, predictor=predictor, num_eval_samples=100)
forecasts = list(forecast_it)
tss = list(ts_it)
plot_forecasts(tss, forecasts, past_length=150, num_plots=3)

问题是:生成的图将预测值置于 0 附近,而不是原始时间序列附近,如示例所示。我做错了什么?

最佳答案

正如 Trenton_M 指出的,这解决了这个问题:

df = pd.read_csv(url, header=0, index_col=0, parse_dates=True)

关于python - 由 Gluon-TS 示例生成的预测约为 0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57791115/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com