Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Oppiskele Implementation in Python | Time Series: Let's Start
Time Series Analysis

bookImplementation in Python

Having become familiar with the models that will allow us to predict time series, you probably have a question, which Python libraries will be used?

Firstly, in order to better understand the mathematical mechanism - you can implement one of the models yourself in Python.

While we will load the rest of the models through libraries such as statsmodels:

import matplotlib.pyplot as plt
import pandas as pd
import seaborn as sns
from statsmodels.tsa.api import acf, graphics, pacf
from statsmodels.tsa.ar_model import AutoReg, ar_select_order

sns.set_style("darkgrid")
pd.plotting.register_matplotlib_converters()
sns.mpl.rc("figure", figsize=(16, 6))
sns.mpl.rc("font", size=14)

data = pd.read_csv("HOUSTNSA.csv")
data = data.set_index("DATE")
housing = data.pct_change().dropna()
housing = 100 * housing.asfreq("MS")
fig, ax = plt.subplots()
ax = housing.plot(ax=ax)
mod = AutoReg(housing, 4, old_names=False)
res = mod.fit()

sel = ar_select_order(housing, 18, old_names=False)
sel.ar_lags
res = sel.model.fit()

fig = res.plot_predict(700, 840)

We have formed a prediction for the next hundred months in the plot above.

The above code uses a model that captures the last "pattern" of seasonality, i.e., the same repeating segment.

Oliko kaikki selvää?

Miten voimme parantaa sitä?

Kiitos palautteestasi!

Osio 1. Luku 4

Kysy tekoälyä

expand

Kysy tekoälyä

ChatGPT

Kysy mitä tahansa tai kokeile jotakin ehdotetuista kysymyksistä aloittaaksesi keskustelumme

Awesome!

Completion rate improved to 3.85

bookImplementation in Python

Pyyhkäise näyttääksesi valikon

Having become familiar with the models that will allow us to predict time series, you probably have a question, which Python libraries will be used?

Firstly, in order to better understand the mathematical mechanism - you can implement one of the models yourself in Python.

While we will load the rest of the models through libraries such as statsmodels:

import matplotlib.pyplot as plt
import pandas as pd
import seaborn as sns
from statsmodels.tsa.api import acf, graphics, pacf
from statsmodels.tsa.ar_model import AutoReg, ar_select_order

sns.set_style("darkgrid")
pd.plotting.register_matplotlib_converters()
sns.mpl.rc("figure", figsize=(16, 6))
sns.mpl.rc("font", size=14)

data = pd.read_csv("HOUSTNSA.csv")
data = data.set_index("DATE")
housing = data.pct_change().dropna()
housing = 100 * housing.asfreq("MS")
fig, ax = plt.subplots()
ax = housing.plot(ax=ax)
mod = AutoReg(housing, 4, old_names=False)
res = mod.fit()

sel = ar_select_order(housing, 18, old_names=False)
sel.ar_lags
res = sel.model.fit()

fig = res.plot_predict(700, 840)

We have formed a prediction for the next hundred months in the plot above.

The above code uses a model that captures the last "pattern" of seasonality, i.e., the same repeating segment.

Oliko kaikki selvää?

Miten voimme parantaa sitä?

Kiitos palautteestasi!

Osio 1. Luku 4
some-alt