# NOT RUN {
#
# A projection pursuit regression example
#
# Load the sample data
data(mtcars)
# Fit a projection pursuit regression model
model <- ppr(mpg ~ ., data = mtcars, nterms = 1)
# Construct variable importance plot
vip(model, method = "firm")
# Better yet, store the variable importance scores and then plot
vi_scores <- vi(model, method = "firm")
vip(vi_scores, geom = "point", horiz = FALSE)
vip(vi_scores, geom = "point", horiz = FALSE, aesthetics = list(size = 3))
# The `%T>\%` operator is imported for convenience; see ?magrittr::`%T>%`
# for details
vi_scores <- model %>%
vi(method = "firm") %T>%
{print(vip(.))}
vi_scores
# Permutation scores (barplot w/ raw values and jittering)
pfun <- function(object, newdata) predict(object, newdata = newdata)
vip(model, method = "permute", train = mtcars, target = "mpg", nsim = 10,
metric = "rmse", pred_wrapper = pfun,
aesthetics = list(color = "grey50", fill = "grey50"),
all_permutations = TRUE, jitter = TRUE)
# Permutation scores (boxplot)
vip(model, method = "permute", train = mtcars, target = "mpg", nsim = 10,
metric = "rmse", pred_wrapper = pfun, geom = "boxplot")
# Permutation scores (boxplot colored by feature)
library(ggplot2) # for `aes_string()` function
vip(model, method = "permute", train = mtcars, target = "mpg", nsim = 10,
metric = "rmse", pred_wrapper = pfun, geom = "boxplot",
all_permutations = TRUE, mapping = aes_string(fill = "Variable"),
aesthetics = list(color = "grey35", size = 0.8))
# }
Run the code above in your browser using DataLab