knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "README-figures/",
  warnings = FALSE
)

Autocompboost

Use case

devtools::load_all()

# Use adult task from OpenML:
task = tsk("oml", task_id = 7592)

# Remove rows with missings:
task$filter(which(complete.cases(task$data())))

# Train compboost learner:
set.seed(31415)
cboost = lrn("classif.compboost", predict_type = "prob", show_output = FALSE,
  learning_rate = 0.1, add_deeper_interactions = TRUE, use_components = FALSE,
  stop_epsylon_for_break = 0, stop_patience = 3L, df = 2,
  ncores = 4L)
cboost$train(task)

Information about the stages:

library(ggplot2, quietly = TRUE)

## How much risk was explained by which stage:
rstages = cboost$getRiskStages()
knitr::kable(rstages)

#rstages = rstages[-1, ]
#rstages$stage = factor(rstages$stage, levels = rstages$stage)
#ggplot(rstages, aes(x = "", y = percentage, fill = stage)) +
#  geom_bar(stat = "identity") +
#  theme(legend.position = "bottom") +
#  coord_flip() +
#  scale_y_reverse() +
#  xlab("") +
#  ylab("") +
#  ggtitle("Explained risk per stage") +
#  labs(fill = "") +
#  ggsci::scale_fill_uchicago()

Univariate model

Feature importance

## Feature importance
cboost$model$univariate$calculateFeatureImportance()
vip = cboost$model$univariate$calculateFeatureImportance(aggregate_bl_by_feat = TRUE)
plotFeatureImportance(cboost$model$univariate)

Partial effects

# Visualize top 4 vars:
fnms = vip$feature[seq_len(4)]
ggs = lapply(fnms, function(nm) plotPEUni(cboost$model$univariate, nm))

library(patchwork)

Reduce("+", ggs)

Pairwise interactions

Feature importance

vip_int = cboost$model$interactions$calculateFeatureImportance()
knitr::kable(vip_int)

plotTensor(cboost$model$interactions, vip_int$baselearner[1]) + theme_minimal()
plotTensor(cboost$model$interactions, vip_int$baselearner[2]) + theme_minimal()
plotTensor(cboost$model$interactions, vip_int$baselearner[3]) + theme_minimal()
plotTensor(cboost$model$interactions, vip_int$baselearner[4]) + theme_minimal()

Prediction decomposition

library(dplyr, quietly = TRUE)

# "new observation"
newdata = task$data()[1234,]
newdata$class = NULL
knitr::kable(t(newdata))

plotIndividualContributionAC(cboost, newdata)


Coorsaa/autocompboost documentation built on March 19, 2023, 12:08 p.m.