【发布时间】:2018-01-12 14:55:25
【问题描述】:
Facebook's Prophet in R(还有一个 Python 版本)用于生成时间序列预测。
模型 m 由以下人员创建:
m <- prophet(df)
future <- make_future_dataframe(m, periods = 365)
forecast <- predict(m, future)
plot(m, forecast)
返回一个格式很好的图表,例如:
我想在图表中添加其他指标,除了那些是 m 和 forecast 的一部分,例如添加由另一个预测生成的预测结果方法等...
但是当我尝试这样的事情时:
plot(m,forecast, arima_model)
我得到一个错误:
Error in uncertainty && exists("yhat_lower", where = df) :
invalid 'x' type in 'x && y'
那么如何将其他数据添加到先知模型图中?
此外,很酷的格式(带有网格的灰色背景、格式正确的日期、颜色方案的不确定性等)从何而来?
我虽然 plot() 可能会从 m 中获取参数,但是当我检查 m 时似乎是一个常规数据框.我看不到任何表明格式化绘图的参数的东西。
names(m)
[1] "growth" "changepoints" "n.changepoints"
[4] "yearly.seasonality" "weekly.seasonality" "daily.seasonality"
[7] "holidays" "seasonality.prior.scale" "changepoint.prior.scale"
[10] "holidays.prior.scale" "mcmc.samples" "interval.width"
[13] "uncertainty.samples" "specified.changepoints" "start"
[16] "y.scale" "logistic.floor" "t.scale"
[19] "changepoints.t" "seasonalities" "extra_regressors"
[22] "stan.fit" "params" "history"
[25] "history.dates"
typeof(m)
[1] "list"
plot() 从哪里获取所有格式?以及如何添加额外的 I 数据来绘制?
【问题讨论】:
-
它使用
ggplot2。如果您在控制台中输入plot.prophet,您可以看到完整的代码。你应该可以像任何 ggplot 一样修改它。 -
Gregor 是对的,你需要 ggplot2。这是一些资源的链接:had.co.nz/ggplot2