官术网_书友最值得收藏!

How to do it...

In the following steps, we demonstrate several methods for making predictions using time series data:

  1. Begin by generating a time series:
from random import random

time_series = [2 * x + random() for x in range(1, 100)]
  1. Plot your data:
%matplotlib inline
import matplotlib.pyplot as plt

plt.plot(time_series)
plt.show()

The following screenshot shows the output:

  1. There is a large variety of techniques we can use to predict the consequent value of a time series:
    • Autoregression (AR):
from statsmodels.tsa.ar_model import AR

model = AR(time_series)
model_fit = model.fit()
y = model_fit.predict(len(time_series), len(time_series))
    • Moving average (MA):
from statsmodels.tsa.arima_model import ARMA

model = ARMA(time_series, order=(0, 1))
model_fit = model.fit(disp=False)
y = model_fit.predict(len(time_series), len(time_series))
    • Simple exponential smoothing (SES):
from statsmodels.tsa.holtwinters import SimpleExpSmoothing

model = SimpleExpSmoothing(time_series)
model_fit = model.fit()
y = model_fit.predict(len(time_series), len(time_series))

The resulting predictions are as follows:

主站蜘蛛池模板: 松桃| 华坪县| 漳州市| 镇雄县| 苍梧县| 本溪市| 玛纳斯县| 遵义市| 阜阳市| 岳阳市| 平山县| 西峡县| 石柱| 德庆县| 永吉县| 凌云县| 托克托县| 鞍山市| 石嘴山市| 泰州市| 浦北县| 嘉鱼县| 巴青县| 五台县| 景东| 东丰县| 克山县| 淮南市| 济南市| 临澧县| 灵宝市| 阳江市| 泗水县| 文化| 饶阳县| 凤山市| 白河县| 延安市| 巴塘县| 策勒县| 绥宁县|