predict_model | R Documentation |
Performs prediction of response
stats::lm()
,
stats::glm()
,
ranger::ranger()
,
mgcv::gam()
,
workflows::workflow()
(i.e., tidymodels
models), and
xgboost::xgb.train()
with binary or continuous
response. See details for more information.
NOTE: You should never need to call this function explicitly. It is exported just to be easier accessible for users, see details.
predict_model(x, newdata, ...)
## Default S3 method:
predict_model(x, newdata, ...)
## S3 method for class 'ar'
predict_model(x, newdata, newreg, horizon, ...)
## S3 method for class 'Arima'
predict_model(
x,
newdata,
newreg,
horizon,
explain_idx,
explain_lags,
y,
xreg,
...
)
## S3 method for class 'forecast_ARIMA'
predict_model(x, newdata, newreg, horizon, ...)
## S3 method for class 'glm'
predict_model(x, newdata, ...)
## S3 method for class 'lm'
predict_model(x, newdata, ...)
## S3 method for class 'gam'
predict_model(x, newdata, ...)
## S3 method for class 'ranger'
predict_model(x, newdata, ...)
## S3 method for class 'workflow'
predict_model(x, newdata, ...)
## S3 method for class 'xgb.Booster'
predict_model(x, newdata, ...)
x |
Model object for the model to be explained. |
newdata |
A data.frame/data.table with the features to predict from. |
... |
|
The following models are currently supported:
stats::lm()
stats::glm()
ranger::ranger()
mgcv::gam()
workflows::workflow()
xgboost::xgb.train()
If you have a binary classification model we'll always return the probability prediction for a single class.
If you are explaining a model not supported natively, you need to create the [predict_model()]
function yourself,
and pass it on to as an argument to [explain()]
.
For more details on how to explain such non-supported 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. Vector of size equal to the number of rows in newdata
.
Martin Jullum
# Load example data
data("airquality")
airquality <- airquality[complete.cases(airquality), ]
# Split data into test- and training data
x_train <- head(airquality, -3)
x_explain <- tail(airquality, 3)
# Fit a linear model
model <- lm(Ozone ~ Solar.R + Wind + Temp + Month, data = x_train)
# Predicting for a model with a standardized format
predict_model(x = model, newdata = x_explain)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.