【问题标题】:Correlation between time series时间序列之间的相关性
【发布时间】:2019-11-03 01:42:06
【问题描述】:

我有一个数据集,其中一个过程被描述为由约 2000 个点和 1500 个维度组成的时间序列。

我想量化每个维度与通过另一种方法测量的另一个时间序列的相关程度。

执行此操作的适当方法是什么(最终在 python 中完成)?我听说 Pearson 不太适合这项任务,至少在没有数据准备的情况下是这样。您对此有何看法?

非常感谢!

【问题讨论】:

  • 您能告诉我们更多关于您的数据性质的信息吗?在一般情况下,我希望 Pearson 相关性可以正常工作。您的数据有什么特别之处吗?
  • 很遗憾,我不能说太多,但大致上数据来自对机械系统的监测(由未命名的变量描述,因此没有先验的专家知识)。

标签: machine-learning time-series data-science


【解决方案1】:

数据科学的一个普遍的好规则是首先尝试简单的事情。只有当简单的事情失败时,你才应该转向更复杂的事情。考虑到这一点,以下是计算每个维度与其他时间序列之间的 Pearson 相关性的方法。这里的关键函数是pearsonr

import numpy as np
from scipy.stats import pearsonr

# Generate a random dataset using 2000 points and 1500 dimensions
n_times = 2000
n_dimensions = 1500
data = np.random.rand(n_times, n_dimensions)

# Generate another time series, also using 2000 points
other_time_series = np.random.rand(n_times)

# Compute correlation between each dimension and the other time series
correlations = np.zeros(n_dimensions)
for dimension in range(n_dimensions):
    # The Pearson correlation function gives us both the correlation
    # coefficient (r) and a p-value (p). Here, we only use the coefficient.
    r, p = pearsonr(data[:, dimension], other_time_series)
    correlations[dimension] = r

# Now we have, for each dimension, the Pearson correlation with the other time
# series!
len(correlations)

# Print the first 5 correlation coefficients
print(correlations[:5])

如果 Pearson 相关性对您不起作用,您可以尝试将 pearsonr 函数换成其他函数,例如:

  • spearmanrSpearman 秩相关系数。
  • kendalltau Kendall 的 tau,序数数据的相关性度量。

【讨论】:

  • 感谢您的回答。实际上,这与我尝试的非常接近,我对用于时间序列相关的方法以及 Pearson 是否与问题相关更感兴趣。这就是为什么我没有提供代码示例的原因:) 也许潜在的问题更多:如果我想计算相关系数,我应该以某种方式预处理数据还是使用 Pearson 系数以外的其他方法。干杯
  • 您的数据是否需要预处理取决于数据的性质。一般来说,只要你所有的时间序列都是普通的浮点数,你就不需要预处理。 Pearson 相关性对数据均值和数据的整体缩放不敏感。
  • 当然,Pearson 相关性对异常值很敏感,因此如果您的数据有一些伪像/故障,这可能是个问题。
  • 好的,数据中确实存在毛刺和噪音,过程取决于外部因素。所以这是意料之中的,因为它是观察过程的一部分。
  • 当您只关心一个时间序列是否随着另一个时间序列的上升而上升时,您将使用 Spearman 等级相关性或 Kendall 的 Tau,而不管它上升了多少。
猜你喜欢
  • 2020-06-23
  • 1970-01-01
  • 1970-01-01
  • 2014-10-08
  • 2014-02-09
  • 2018-06-22
  • 2017-01-11
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多