nano_tree_plot: Create Tree Diagram

View source: R/nano_tree_plot.R

nano_tree_plotR Documentation

Create Tree Diagram

Description

Create tree diagram from a tree-based model.

Usage

nano_tree_plot(nano, grid_no = nano$n_model, tree_number = 1, tree_class = NA)

Arguments

nano

a nano object.

grid_no

a numeric. Slot number of model to plot tree diagram of.

tree_number

a numeric. Number of tree to plot.

tree_class

a character. Only valid for multinomial classification. Specific class of response variable to plot tree diagram of.

Details

Plots a tree diagram of a specific tree built by a tree-based model (algorithm = drf or gbm) stored in a nano object. Note, a drf or gbm usually builts hundreds of different trees, whose individual predictions are averaged to obtain the final prediction. However, only a single of these trees can be plotted at a time using this function.

This function is adapted from the code in the following webpage: "https://www.h2o.ai/blog/finally-you-can-plot-h2o-decision-trees-in-r/". This code converts the information from the h2o model into a Node object using the data.tree pacakge and then is visualised using the DiagrammeR package.

Examples

## Not run: 
if(interactive()){
 library(h2o)
 library(nano)
 
 nano.init()
 
 # import dataset
 data(property_prices)
 
 # create model
 nano <- nano_grid(data     = data, 
                   response = "sale_price",
                   algo     = "gbm",
                   ntrees   = 10)
                     
 # create tree diagram of the 5th tree build by GBM model
 tree <- nano_tree_plot(nano, 1, 5)
 # plot tree diagram
 plot(tree)
 
 }

## End(Not run)

Nanoputian628/nano documentation built on Oct. 30, 2023, 3:28 p.m.