prophet
prophet copied to clipboard
Feature request: Allow access to raw samples for predictions.
As prophet is using stan
as backend, I noticed that there are internal functions available to access the raw samples for a prediction instead of just the mean and confidence limits. This would be awesome if it was exposed in a function, perhaps as an option to predict.prophet
.
I created an example of a separate function that does this. Let me know if you would like it integrated in another function or as a standalone function. I can then create a pull request for it.
Best regards.
Example function:
predictsamples.prophet <- function (object, df = NULL, ...) {
if (is.null(object$history)) {
stop("Model must be fit before predictions can be made.")
}
if (is.null(df)) {
df <- object$history
} else {
if (nrow(df) == 0) {
stop("Dataframe has no rows.")
}
out <- prophet:::setup_dataframe(object, df)
df <- out$df
}
df$trend <- prophet:::predict_trend(object, df)
samples <- prophet:::sample_posterior_predictive(object, df)
return(samples$yhat)
}
Does the predictive_samples()
function suit your use case?