当前位置:网站首页>机器学习笔记 - 自相关和偏自相关简介
机器学习笔记 - 自相关和偏自相关简介
2022-06-30 12:14:00 【坐望云起】
1、概述
自相关和偏自相关图在时间序列分析和预测中大量使用。
这些图表以图形方式总结了与时间序列中的观测值的关系强度以及先前时间步长的观测值。对于时间序列预测的初学者来说,自相关和偏自相关之间的区别可能很让人困惑。
我们将了解如何使用 Python 计算和绘制自相关和偏相关图。以及了解以下内容
如何绘制和查看时间序列的自相关函数。
如何绘制和查看时间序列的偏自相关函数。
用于时间序列分析的自相关函数和偏自相关函数之间的区别。
2、最低每日温度数据集
该数据集描述了澳大利亚墨尔本市 10 年(1981-1990 年)的最低日气温。
单位为摄氏度,有 3,650 个观测值。数据来源为澳大利亚气象局。
数据集下载地址
链接:https://pan.baidu.com/s/19G9YsOKtRDXNYAKdOwBq6A
提取码:ateb
下面加载最低每日温度并绘制时间序列图。
from pandas import read_csv
from matplotlib import pyplot
series = read_csv('daily-minimum-temperatures.csv', header=0, index_col=0)
series.plot()
pyplot.show()
运行该示例将数据集加载为 Pandas 系列并创建时间序列的线图。

3、相关和自相关
相关性总结了两个变量之间关系的强度。我们可以假设每个变量的分布符合高斯(钟形曲线)分布。如果是这种情况,我们可以使用皮尔逊相关系数来总结变量之间的相关性。
Pearson 相关系数是介于 -1 和 1 之间的数字,分别描述负相关或正相关。零值表示没有相关性。
我们可以计算时间序列观测值与先前时间步长的观测值的相关性,称为滞后。因为时间序列观测值的相关性是使用先前时间相同序列的值计算的,所以这称为序列相关性或自相关性。
时间序列自相关的滞后图称为AutoCorrelation Function,或首字母缩写词 ACF。该图有时称为相关图或自相关图。
下面是使用 statsmodels 库中的plot_acf()函数计算和绘制最低每日温度的自相关图的示例。
from pandas import read_csv
from matplotlib import pyplot
from statsmodels.graphics.tsaplots import plot_acf
series = read_csv('daily-minimum-temperatures.csv', header=0, index_col=0)
plot_acf(series)
pyplot.show()
运行该示例会创建一个 2D 图,显示沿 x 轴的滞后值以及在 -1 和 1 之间的 y 轴上的相关性。
置信区间绘制为圆锥。默认情况下,这设置为 95% 的置信区间,这表明此代码之外的相关值很可能是相关性而不是统计侥幸。

默认情况下,会打印所有滞后值,这会使绘图变得嘈杂。我们可以将 x 轴上的滞后数限制为 50,以使绘图更易于阅读。

4、偏自相关函数
偏自相关是时间序列中的观察与先前时间步的观察之间的关系的总结,而干预观察的关系被删除。
观测值和前一时间步的观测值的自相关由直接相关和间接相关组成。这些间接相关性是观察相关性的线性函数,在干预时间步上观察。
偏自相关函数试图消除的正是这些间接相关性。
下面的示例使用statsmodels 库中的plot_pacf()计算并绘制了最低每日温度数据集中前 50 个滞后的偏自相关函数。
from pandas import read_csv
from matplotlib import pyplot
from statsmodels.graphics.tsaplots import plot_pacf
series = read_csv('daily-minimum-temperatures.csv', header=0, index_col=0)
plot_pacf(series, lags=50)
pyplot.show()

边栏推荐
- Splitting e-commerce systems into micro services
- Charles打断点修改请求数据&响应数据
- Lichuang EDA learning notes 10 common connector component identification and passive buzzer driving circuit
- Pharmacy management system
- Redis cache problem
- How to use the plug-in mechanism to gracefully encapsulate your request hook
- grep匹配查找
- [leetcode] 15. Sum of three numbers
- Mysql判断计算结果,除以100
- Building a database model using power designer tools
猜你喜欢
随机推荐
Dataworks synchronizes maxcomputer to sqlserver. Chinese characters become garbled. How can I solve it
RDS MySQL数据迁移PolarDB MySQL费用可以转过去吗?
Redis cache problem
How to use the plug-in mechanism to gracefully encapsulate your request hook
Solve the problem that the server cannot be connected via SSH during reinstallation
60 个神级 VS Code 插件!!
Analysis of the whole process of common tilt data processing in SuperMap idesktop
21. Notes on WPF binding
Understanding and learning of MySQL indexing and optimization
海思3559开发常识储备:相关名词全解
Substrate 源码追新导读: Call调用索引化, 存储层事物化全面完成
Commands for redis basic operations
Substrate 源码追新导读: Pallet Alliance 并入主线,
How to select an OLAP database engine?
全面解析免费及收费SSH工具的基本特性和总结
Introduction to the novelty of substrate source code: comprehensive update of Boca system Boca weight calculation, optimization and adjustment of governance version 2.0
JMeter性能测试之相关术语及性能测试通过标准
Wechat launched the picture big bang function; Apple's self-developed 5g chip may have failed; Microsoft solves the bug that causes edge to stop responding | geek headlines
QT MSVC installation and commissioning
【一天学awk】正则匹配