prophet翻译(八)--- 异常值

异常值

异常值可以影响Prophet的预测结果,主要有两种方式。下面的示例中,我们使用之前提到的R页面的日志化维基百科访问量数据进行预测,但添加了一段错误的数据:

# Python
df = pd.read_csv('https://raw.githubusercontent.com/facebook/prophet/main/examples/example_wp_log_R_outliers1.csv')
m = Prophet()
m.fit(df)
future = m.make_future_dataframe(periods=1096)
forecast = m.predict(future)
fig = m.plot(forecast)

image

在上述示例中,趋势的预测看起来是合理的,但不确定性区间似乎过于宽广。Prophet能够处理历史中的异常值,但是只能通过拟合趋势变化来处理它们。因此,不确定性模型预期未来的趋势变化具有类似的幅度。

处理异常值的最佳方法是将其移除- Prophet对缺失数据没有问题。如果在历史数据中将异常值的值设置为NA(缺失值),但保留未来的日期,那么Prophet将为异常值给出预测。

# Python
df.loc[(df['ds'] > '2010-01-01') & (df['ds'] < '2011-01-01'), 'y'] = None
model = Prophet().fit(df)
fig = model.plot(model.predict(future))

image
在上面的示例中,异常值扰乱了不确定性估计,但并没有影响到主要的预测值yhat。然而,并不是所有情况下都是如此,就像在下面这个示例中添加了异常值的情况一样:

# Python
df = pd.read_csv('https://raw.githubusercontent.com/facebook/prophet/main/examples/example_wp_log_R_outliers2.csv')
m = Prophet()
m.fit(df)
future = m.make_future_dataframe(periods=1096)
forecast = m.predict(future)
fig = m.plot(forecast)

image
在这个示例中,2015年6月的一组极端异常值扰乱了季节性的估计,因此它们的影响会一直持续到未来。同样,正确的方法是将它们移除:

# Python
df.loc[(df['ds'] > '2015-06-01') & (df['ds'] < '2015-06-30'), 'y'] = None
m = Prophet().fit(df)
fig = m.plot(m.predict(future))

image

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章