2

我正在尝试为此处发布的大约 2 年的日期时间数据拟合曲线,并预测一年的 5 分钟间隔。我正在使用带有此输入数据的Facebook Prophet

无论我是进行线性拟合还是逻辑拟合,我都会得到一些比任何输入值更大或更小的离谱值(线性模型甚至会产生负值)。我试图利用逻辑模型来指定底限和上限,但这也没有阻止异常数字。

例如,在输出的 105120 条预测记录中,有 25131 条低于指定的下限。有人可以告诉我我做错了什么吗?或者,如果有预期的行为我没有正确解释?

library(prophet)
library(dplyr)

url <- 'https://gist.githubusercontent.com/thomasnield/501b355a24a3a5f736b2c8510bfb0098/raw/b9dedf2f4170e3dc20cf7c1d2f39f2c2ef66b954/gistfile1.txt'

df <- read.csv(url) %>% mutate(y=log(y))

#floor and cap
lower = quantile(df$y, .05)
upper = quantile(df$y, .95)

df <- df %>% mutate(floor = lower, cap = upper)

# modeling
m <- prophet(df, 
             changepoint.prior.scale=0.01, 
             growth = 'logistic')

future <- make_future_dataframe(m, periods = (24*12*365), 
                                freq = 60 * 5, 
                                include_history = FALSE)  %>% mutate(floor = lower, cap = upper)
# forecast every 5 minutes
forecast <- predict(m,future)
#prophet_plot_components(m, forecast)

write.csv(forecast %>% 
            select(ds, yhat_lower, yhat_upper, yhat) %>% 
            mutate(floor = exp(lower), 
                   cap = exp(upper),
                   ln_yhat_lower = yhat_lower,
                   ln_yhat_upper = yhat_upper, 
                   ln_yhat = yhat,
                   ln_floor = lower, 
                   ln_cap = upper,
                   yhat_lower = exp(yhat_lower), 
                   yhat_upper = exp(yhat_upper), 
                   yhat = exp(yhat)
                   ), 'problem_output.csv')
4

0 回答 0