Logo
Section 1 / 9

常见模式

了解时间序列数据中的一些常见模式以及如何解读它们。

导入

常见模式

了解时间序列数据中的一些常见模式以及如何解读它们。

import pandas as pd import matplotlib.pyplot as plt from statsmodels.graphics.tsaplots import plot_acf

df = pd.read_csv('airpassengers.csv')

更改数据类型

df["Month"] = pd.to_datetime(df['Month'], format='%Y-%m')

将日期设置为索引

df = df.set_index('Month')

绘制自相关图(ACF)

fig, axe = plt.subplots(figsize=(6,5)) axe.set_xlabel('滞后阶数') axe.set_ylabel('相关性') fig = plot_acf(df['Passengers'], ax=axe, alpha=0.05)

显示并保存图像

fig.savefig("output/output.png") plt.close(fig)

import pandas as pd import matplotlib.pyplot as plt from statsmodels.graphics.tsaplots import plot_acf

df = pd.read_csv('seattle_weather.csv')

更改数据类型

df["date"] = pd.to_datetime(df['date'], format='%Y-%m-%d')

将日期设置为索引

df = df.set_index('date')

绘制自相关图(ACF)

fig, axe = plt.subplots(figsize=(6,5)) axe.set_xlabel('滞后阶数') axe.set_ylabel('相关性') fig = plot_acf(df['temp_max'], lags=180, ax=axe, alpha=0.05)

显示并保存图像

fig.savefig("output/output.png") plt.close(fig)

预测评估

移动平均