具有非线性趋势的Detrend磁通时间序列

2024-05-23 07:45:30 发布

您现在位置:Python中文网/ 问答频道 /正文

我需要去趋势通量时间序列数据(光曲线),但我遇到了一个问题,当时间序列数据没有一个简单的线性趋势。在

我一直在用scipy.signal.detrend公司()对于线性情况的去趋势化,但这还不够。在

我用过纽比.波利菲特()尝试多项式去趋势化,但我不确定如何处理它返回的多项式系数。在

有人能告诉我下一步该怎么做吗?或者,如果有人有更好的方法去呈现非线性数据,我也很乐意听到。在


Tags: 数据方法signal时间情况公司序列线性
1条回答
网友
1楼 · 发布于 2024-05-23 07:45:30

简单地说,您获取polyfit返回的系数,并将它们传递给polyval,以计算观察到的“x”位置处的多项式。在

作为一个独立的示例,假设我们有类似于以下内容的内容:

import numpy as np
import matplotlib.pyplot as plt

num = 1000
x = np.linspace(0, 10, num)
y = np.exp(x)

# Add some non-stationary noise that's hard to see without de-trending
noise = 100 * np.exp(0.2 * x) * np.random.normal(0, 1, num)
y += noise

fig, ax = plt.subplots()
ax.plot(x, y, 'ro')
plt.show()

enter image description here

注意,这里我没有使用多项式函数来创建y。那是故意的。否则,我们将得到精确的拟合,而不需要“玩弄”多项式的阶数。在

现在让我们用一个二阶多项式函数(注意model = np.polyfit(x, y, 2)行中的2):

^{pr2}$

enter image description here


请注意,我们没有完全拟合数据。这是一个指数函数,我们用的是多项式。然而,当我们增加多项式的阶数时,我们将更精确地拟合函数(冒着开始拟合噪声的风险):

enter image description here

enter image description here

enter image description here

enter image description here

相关问题 更多 >

    热门问题