Learn R Programming

dtGAP (version 0.0.2)

compute_tree: Compute Decision Tree Data for Plotting and Analysis

Description

Builds and processes a decision tree model object to prepare data for plotting, including layout positions and terminal node summaries. need to run util.R first

Usage

compute_tree(
  fit = NULL,
  model = c("rpart", "party", "C50", "caret", "cforest"),
  show = c("all", "train", "test"),
  data = NULL,
  target_lab = NULL,
  task = c("classification", "regression"),
  custom_layout = NULL,
  panel_space = 0.001
)

Value

A list with components:

  • fit: the original fitted model

  • dat: data.frame of observations with node assignments and predictions

  • plot_data: data.frame of nodes with plotting variables and probabilities

  • layout: data.frame of node x/y positions

Arguments

fit

A fitted decision party tree object.

model

Character. Which implementation to use: one of "rpart", "party", "C50", or "caret".

show

Character. Which subset to return: "all", "train" or "test" .

data

A data.frame containing the features and target for prediction.

target_lab

Character. Name of the target column.

task

Character. Task type: "classification" or "regression".

custom_layout

Optional data.frame with custom node positions (columns: id, x, y).

panel_space

Numeric. Vertical spacing between panels in layout.

Examples

Run this code
# \donttest{
library(rpart)
library(partykit)
library(ggparty)
library(dplyr)
data <- add_data_type(
  data_all = Psychosis_Disorder
)
data <- prepare_features(
  data,
  target_lab = "UNIQID",
  task = "classification"
)
fit <- train_tree(
  data = data, target_lab = "UNIQID",
  model = "rpart"
)$fit
tree_res <- compute_tree(
  fit,
  model = "rpart", show = "all",
  data = data, target_lab = "UNIQID",
  task = "classification"
)
tree_res$dat
tree_res$plot_data
# }

Run the code above in your browser using DataLab