Consistent prediction following tidymodels principles
OTHER License
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
out.width = "100%"
)
options(tibble.print_min = 5, tibble.print_max = 5)
set.seed(27)
safepredict
has two goals: to provide a consistent interface to prediction via the safe_predict()
generic, and to accurately quantify prediction uncertainty.
safe_predict()
:
safepredict
follows the tidymodels prediction specification.
safepredict
is currently in the beginning stages of development and is available only on Github. You can install it with:
# install.packages("devtools")
devtools::install_github("alexpghayes/safepredict")
The three main arguments to safe_predict()
are always the same:
object
: A model object you would like to get predictions from.
new_data
: Required. Data in the same format as required for the
predict()
method.
type
: What kind of predictions you would like. Options are:
type | application |
---|---|
response |
numeric predictions |
class |
hard class predictions |
prob |
class probabilities, survivor probabilities |
link |
glm linear predictor |
conf_int |
confidence intervals |
pred_int |
prediction intervals |
Suppose you fit a logistic regression using glm
:
library(tibble)
data <- tibble(
y = as.factor(rep(c("A", "B"), each = 50)),
x = c(rnorm(50, 1), rnorm(50, 3))
)
fit <- glm(y ~ x, data, family = binomial)
You can predict class probabilities:
library(safepredict)
test <- tibble(x = rnorm(10, 2))
safe_predict(fit, new_data = test, type = "prob")
or can jump straight to hard class decisions
safe_predict(fit, new_data = test, type = "class")
We can also get predictions on the link scale:
safe_predict(fit, new_data = test, type = "link")
or we can get confidence intervals on the response scale
safe_predict(fit, new_data = test, type = "conf_int")
parsnip
provides a consistent interface to supervised models. Eventually safepredict
will act as the prediction backend for parsnip
.
broom
summarizes key information about models in tidy tibbles.
The many ongoing tidymodels
projects.
The prediction
package by Thomas Leeper. prediction
supports a much wider variety of models than safepredict
at the moment, but makes fewer consistency guarantees.