Learn R Programming

shapr (version 0.1.3)

predict_model: Generate predictions for different model classes

Description

Performs prediction of response lm, glm, ranger, mgcv::gam and xgboost::xgb.train with binary or continuous response. See details for more information.

Usage

predict_model(x, newdata)

# S3 method for default predict_model(x, newdata)

# S3 method for lm predict_model(x, newdata)

# S3 method for glm predict_model(x, newdata)

# S3 method for ranger predict_model(x, newdata)

# S3 method for xgb.Booster predict_model(x, newdata)

# S3 method for gam predict_model(x, newdata)

Arguments

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.

Value

Numeric

Details

The following models are currently supported:

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 use a custom model see the package vignette: vignette("understanding_shapr", package = "shapr")

Examples

Run this code
# NOT RUN {
# 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)
# }

Run the code above in your browser using DataLab