- Machine Learning for Cybersecurity Cookbook
- Emmanuel Tsukerman
- 136字
- 2021-06-24 12:28:58
How to do it...
In the following steps, we demonstrate several methods for making predictions using time series data:
- Begin by generating a time series:
from random import random
time_series = [2 * x + random() for x in range(1, 100)]
- Plot your data:
%matplotlib inline
import matplotlib.pyplot as plt
plt.plot(time_series)
plt.show()
The following screenshot shows the output:

- 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:

推薦閱讀
- Canvas LMS Course Design
- OpenStack for Architects
- 輕松學(xué)Java Web開發(fā)
- Spark編程基礎(chǔ)(Scala版)
- 輕松學(xué)PHP
- 機(jī)器人智能運(yùn)動(dòng)規(guī)劃技術(shù)
- 智能工業(yè)報(bào)警系統(tǒng)
- Maya 2012從入門到精通
- 所羅門的密碼
- ASP.NET 2.0 Web開發(fā)入門指南
- 和機(jī)器人一起進(jìn)化
- 機(jī)器學(xué)習(xí)案例分析(基于Python語(yǔ)言)
- 牛津通識(shí)讀本:大數(shù)據(jù)(中文版)
- 單片機(jī)C語(yǔ)言編程實(shí)踐
- 網(wǎng)絡(luò)設(shè)備規(guī)劃、配置與管理大全(Cisco版)