[英]Trend or Shift Detection in python?
Is there any library which detects trends and shift in data automatically in python, I have searched on the internet but could not find any library. python中是否有任何库可以自动检测趋势和数据变化,我在互联网上搜索但找不到任何库。
Nor I have found any working examples, I found some papers but they weren't that helpful.我也没有找到任何工作示例,我找到了一些论文,但它们并没有那么有用。
So if anyone knows a library or practical implementation for pls do suggest me.因此,如果有人知道图书馆或实际实现,请建议我。
Have you had a look at scipy ?你看过scipy吗? Self-description:
自我描述:
"SciPy (pronounced “Sigh Pie”) is a Python-based ecosystem of open-source software for mathematics, science, and engineering."
“SciPy(发音为“Sigh Pie”)是一个基于 Python 的数学、科学和工程开源软件生态系统。”
There is also a tutorial about detrending data with scipy.还有一个关于使用 scipy 去趋势数据的教程。
import numpy as np
from matplotlib import pyplot as plt
from scipy import signal
n = 150
t = np.linspace(0, 10, n)
x_raw = .4 * t + np.random.normal(size=n)
x = signal.detrend(x_raw)
plt.figure(figsize=(5, 4))
plt.plot(t, x_raw, label="Raw data")
plt.plot(t, x, label="After Trend Removal")
plt.legend(loc='best')
plt.show()
Update:更新:
Sadly there is no argument for signaltools.detrend
to directly get the trend.遗憾的是,
signaltools.detrend
没有理由直接了解趋势。 Of course, one could simple edit the method or do a linear regression by hand.当然,可以简单地编辑方法或手动进行线性回归。
But the quickest way to implement this seems to be this:但实现这一点的最快方法似乎是这样的:
import numpy as np
from matplotlib import pyplot as plt
from scipy import signal
n = 150
t = np.linspace(0, 10, n)
x_raw = .4 * t + np.random.normal(size=n)
x = signal.detrend(x_raw)
d = x_raw - x
is_positive_trend = d[-1] > d[0]
m = "+" if is_positive_trend else "-"
plt.figure(figsize=(5, 4))
plt.plot(t, x_raw, label=f"Raw data ({m})")
plt.plot(t, d)
plt.legend(loc='best')
plt.show()
Calulate the delta d = x_raw - x
between raw data and detrended data.计算原始数据和去趋势数据之间的 delta
d = x_raw - x
。 The trend is positive, when the last x -value is larger than the first: is_positive_trend = d[-1] > d[0]
当最后一个x值大于第一个时,趋势是正的:
is_positive_trend = d[-1] > d[0]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.