facebook / facebook/prophet

Feature request: Allow access to raw samples for predictions.

Open
#2,137 1 comment 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
Python
Stars
20.4k
Forks
4.6k
Avg merge
19h 52m
Merged PRs (30d)
1

Description

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)
}
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.