如何从TBAT的预测中提取趋势成分(在Python中)?
我正在尝试使用TBAT来预测一个非常简单的时代系列(如所建议的在这里)。这是我正在使用的代码:
#imports
import pandas as pd
import numpy as np
import matplotlib.pylab as plt
from tbats import BATS, TBATS
#build a time series
t_max = 500
np.random.seed(2342)
t = np.array(range(0, t_max))
y = 5 * np.sin(t * 2 * np.pi / 7) + \
2 * np.cos(t * 2 * np.pi / 30.5) + \
((t / 20) ** 1.5 + np.random.normal(size = t_max) * t / 50) + 10
# Create a train-test set. The forecast begins at t_fcst + 1
t_fcst = int(t_max * .75)
# this is how long we want to forecast in the future
forecast_period = t_max - t_fcst
train = y[:t_fcst]
t_train = t[:t_fcst]
test = y[-forecast_period:]
t_test = t[-forecast_period:]
# Create estimator
estimator = TBATS(seasonal_periods=[7, 30.5], use_trend = True)
# Fit model
fitted_model = estimator.fit(train)
y = fitted_model.forecast(steps = forecast_period)
fig, ax = plt.subplots(figsize = (14, 8))
ax.plot(t_train, train, label = 'Train')
ax.plot(t_test, test, label = 'Test')
ax.plot(t_test, y, label = 'Forecast')
ax.legend(loc="upper left")
这就是我得到的:
如果代替:
estimator = TBATS(seasonal_periods=[7, 30.5], use_trend = True)
我使用:
estimator = TBATS(seasonal_periods=[7, 30.5], use_trend = False)
这是我得到的:
知道我在做什么错吗?谢谢
I'm trying to use TBATS to forecast a very simple times series (as suggested here).This is the code I'm using:
#imports
import pandas as pd
import numpy as np
import matplotlib.pylab as plt
from tbats import BATS, TBATS
#build a time series
t_max = 500
np.random.seed(2342)
t = np.array(range(0, t_max))
y = 5 * np.sin(t * 2 * np.pi / 7) + \
2 * np.cos(t * 2 * np.pi / 30.5) + \
((t / 20) ** 1.5 + np.random.normal(size = t_max) * t / 50) + 10
# Create a train-test set. The forecast begins at t_fcst + 1
t_fcst = int(t_max * .75)
# this is how long we want to forecast in the future
forecast_period = t_max - t_fcst
train = y[:t_fcst]
t_train = t[:t_fcst]
test = y[-forecast_period:]
t_test = t[-forecast_period:]
# Create estimator
estimator = TBATS(seasonal_periods=[7, 30.5], use_trend = True)
# Fit model
fitted_model = estimator.fit(train)
y = fitted_model.forecast(steps = forecast_period)
fig, ax = plt.subplots(figsize = (14, 8))
ax.plot(t_train, train, label = 'Train')
ax.plot(t_test, test, label = 'Test')
ax.plot(t_test, y, label = 'Forecast')
ax.legend(loc="upper left")
And this is what I get:
If instead of:
estimator = TBATS(seasonal_periods=[7, 30.5], use_trend = True)
I use:
estimator = TBATS(seasonal_periods=[7, 30.5], use_trend = False)
This is what I get:
Any idea what I'm doing wrong? Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论