predict_model | R Documentation |
Performs prediction of response lm
, glm
,
ranger
, mgcv::gam
and
xgboost::xgb.train
with binary or continuous
response. See details for more information.
predict_model(x, newdata)
## Default S3 method:
predict_model(x, newdata)
## S3 method for class 'lm'
predict_model(x, newdata)
## S3 method for class 'glm'
predict_model(x, newdata)
## S3 method for class 'ranger'
predict_model(x, newdata)
## S3 method for class 'xgb.Booster'
predict_model(x, newdata)
## S3 method for class 'gam'
predict_model(x, newdata)
x |
Model object for the model to be explained. |
newdata |
A data frame (or matrix) in which to look for variables with which to predict. |
The following models are currently supported:
stats::lm
stats::glm
ranger::ranger
mgcv::gam
xgboost::xgb.train
The returned object p
always satisfies the following properties:
is.atomic(p)
equals TRUE
is.double(p)
equals TRUE
If you have a binary classification model we'll always return the probability prediction for a single class.
For more details on how to explain other types of models (i.e. custom models), see the Advanced usage section
of the vignette:
From R: vignette("understanding_shapr", package = "shapr")
Web: https://norskregnesentral.github.io/shapr/articles/understanding_shapr.html#explain-custom-models
Numeric
Martin Jullum
if (requireNamespace("MASS", quietly = TRUE)) {
# Load example data
data("Boston", package = "MASS")
# Split data into test- and training data
x_train <- head(Boston, -3)
x_test <- tail(Boston, 3)
# Fit a linear model
model <- lm(medv ~ lstat + rm + dis + indus, data = x_train)
# Predicting for a model with a standardized format
predict_model(x = model, newdata = x_test)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.