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

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:

主站蜘蛛池模板: 平泉县| 乐昌市| 桂平市| 腾冲县| 吐鲁番市| 汕尾市| 汝州市| 黑山县| 启东市| 伊宁市| 聂荣县| 石渠县| 连州市| 海林市| 玉林市| 三都| 五常市| 长沙市| 惠水县| 长泰县| 阿克苏市| 新郑市| 庆云县| 都江堰市| 土默特右旗| 许昌市| 邳州市| 车致| 克山县| 高邮市| 乌什县| 金沙县| 溆浦县| 北安市| 冀州市| 来宾市| 牡丹江市| 罗城| 金山区| 城固县| 赤城县|