summarise_partials: Summarise partial dependence across resamples

View source: R/partials.R

summarise_partialsR Documentation

Summarise partial dependence across resamples

Description

Summarise partial dependence across resamples

Usage

summarise_partials(object, fns = list(location = mean, spread = stats::sd))

Arguments

object

an object output by ⁠[partials()]⁠, which contains a partial column.

fns

a list of summary functions; one should be called location and be used to compute the central location of the variable (e.g., mean, median, etc.); another should be called spread and be used to compute the spread around that location (e.g., sd, mad, etc.). When fns is NULL, the partial dependence is just concatenated across resamples.

Value

A data.frame with:

  • variable: the variable whose dependence to is computed;

  • value: the value of the variable at which the model marginal effects are computed.

  • yhat or yhat_loc+yhat_spr: the average prediction of the model for this value. either as is or the summary of its location (loc) and spread (spr) according to the functions in fns.

See Also

Other partial dependence plots functions: partials(), plot_partials()

Examples

# fit a model on 5 bootstraps
m <- resample_boot(mtcars, 5) %>%
  xgb_fit(resp="mpg", expl=c("cyl", "hp", "qsec"),
    eta=0.1, max_depth=4, nrounds=20)
# assess variable importance
importance(m) %>% summarise_importance()

# compute the partial dependence to the two most relevant variables
m <- partials(m, expl=c("hp", "cyl"))
# and plot them for each resample
plot_partials(m, fns=NULL)
# do the same with a finer grid
m <- partials(m, expl=c("hp", "cyl"), grid.resolution=50)
plot_partials(m, fns=NULL)
# or along quantiles
m <- partials(m, expl=c("hp", "cyl"), quantiles=TRUE, probs=0:20/20)
plot_partials(m, fns=NULL)

# compute mean+/-sd among resamples
summarise_partials(m)
plot_partials(m)
# do the same with median+/-mad
summarise_partials(m, fns=list(location=median, spread=mad))
plot_partials(m, fns=list(location=median, spread=mad))

jiho/joml documentation built on Dec. 6, 2023, 5:50 a.m.