问题描述
我有一个如下时序数据:
ds y
0 2016-10-31 2000
1 2016-11-30 3000
2 2016-12-31 5000
3 2017-01-31 5000
4 2017-02-28 4000
5 2017-03-31 4500
6 2017-04-30 10000
7 2017-05-31 6500
8 2017-06-30 3500
9 2017-07-31 5500
10 2017-08-31 2000
11 2017-09-30 3000
12 2017-10-31 10000
13 2017-11-30 5000
14 2017-12-31 4000
15 2018-01-31 4500
16 2018-02-28 5000
17 2018-03-31 6500
18 2018-04-30 3500
19 2018-05-31 5500
20 2018-06-30 2000
21 2018-07-31 3000
22 2018-08-31 10000
23 2018-09-30 5000
24 2018-10-31 4000
25 2018-11-30 4500
26 2018-12-31 5000
27 2019-01-31 6500
28 2019-02-28 3500
29 2019-03-31 5500
我已经应用FB Prophet变更点检测算法来提取变更点。
当我在代码中指定5个变更点时,得到以下变更点:
5 2017-03-31
9 2017-07-31
14 2017-12-31
18 2018-04-30
23 2018-09-30
当我在代码中指定7个变更点时,得到以下变更点:
3 2017-01-31
7 2017-05-31
10 2017-08-31
13 2017-11-30
16 2018-02-28
20 2018-06-30
23 2018-09-30
为什么算法没有检测到点6、12、22的值与前一个点相比变化最大?
下面的代码:
from fbprophet import Prophet
import pandas as pd
import matplotlib.pyplot as plt
m = Prophet(growth='linear',n_changepoints = 7,changepoint_range=0.8,changepoint_prior_scale=0.5)
m.fit(df)
future = m.make_future_dataframe(freq = 'M',periods=3)
fcst = m.predict(future)
from fbprophet.plot import add_changepoints_to_plot
fig = m.plot(fcst)
a = add_changepoints_to_plot(fig.gca(),m,fcst)
m.changepoints
解决方法
更改点是一种度量,用于计算数据的趋势在何处更改。您的点6、12和22是异常值,或者可能是假日效应。变更点无法以可靠的方式解决此问题。先知以您的7个变更点示例为例,分析了以下趋势线:
2016-10-31 - 2016-12-31
2016-12-31 - 2017-05-31
2017-05-31 - 2017-08-31
2017-08-31 - 2017-11-30
2017-11-30 - 2018-02-28
2018-02-28 - 2018-06-30
2018-06-30 - 2018-09-30
2018-09-30 - 2019-03-31 (and beyond)