Learn R Programming

explore (version 0.8.0)

explain_tree: Explain a target using a simple decision tree (classification or regression)

Description

Explain a target using a simple decision tree (classification or regression)

Usage

explain_tree(
  data,
  target,
  n,
  max_cat = 10,
  max_target_cat = 5,
  maxdepth = 3,
  minsplit = NA,
  cp = 0,
  weights = NA,
  size = 0.7,
  out = "plot",
  ...
)

Value

Plot or additional the model (if out = "model")

Arguments

data

A dataset

target

Target variable

n

weigths variable (for count data)

max_cat

Drop categorical variables with higher number of levels

max_target_cat

Maximum number of categories to be plotted for target (except NA)

maxdepth

Maximal depth of the tree (rpart-parameter)

minsplit

The minimum number of observations that must exist in a node to split.

cp

Complexity parameter (rpart-parameter)

weights

Vector containing weight of each observation (rpart-parameter). Can not be used in combination with parameter n (variable containing weight for count-data)

size

Textsize of plot

out

Output of function: "plot" | "model"

...

Further arguments

Examples

Run this code
data <- iris
data$is_versicolor <- ifelse(iris$Species == "versicolor", 1, 0)
data$Species <- NULL
explain_tree(data, target = is_versicolor)

Run the code above in your browser using DataLab