isotree.plot.tree: Plot Tree from Isolation Forest Model

View source: R/isoforest.R

isotree.plot.treeR Documentation

Plot Tree from Isolation Forest Model

Description

Plots a given tree from an isolation forest model.

Requires the 'DiagrammeR' library to be installed.

Note that this is just a wrapper over isotree.to.graphviz + 'DiagrammeR::grViz'.

Usage

isotree.plot.tree(
  model,
  output_tree_num = FALSE,
  tree = 1L,
  column_names = NULL,
  column_names_categ = NULL,
  nthreads = model$nthreads,
  width = NULL,
  height = NULL
)

Arguments

model

An Isolation Forest object as returned by isolation.forest.

output_tree_num

Whether to make the statements / outputs return the terminal node number instead of the isolation depth. The numeration will start at one.

tree

Tree for which to generate SQL statements or other outputs. If passed, will generate the statements only for that single tree. If passing 'NULL', will generate statements for all trees in the model.

column_names

Column names to use for the numeric columns. If not passed and the model was fit to a 'data.frame', will use the column names from that 'data.frame', which can be found under 'model$metadata$cols_num'. If not passing it and the model was fit to data in a format other than 'data.frame', the columns will be named 'column_N' in the resulting SQL statement. Note that the names will be taken verbatim - this function will not do any checks for e.g. whether they constitute valid SQL or not when exporting to SQL, and will not escape characters such as double quotation marks when exporting to SQL.

column_names_categ

Column names to use for the categorical columns. If not passed, will use the column names from the 'data.frame' to which the model was fit. These can be found under 'model$metadata$cols_cat'.

nthreads

Number of parallel threads to use.

width

Width for the plot, to pass to 'DiagrammeR::grViz'.

height

Height for the plot, to pass to 'DiagrammeR::grViz'.

Details

In general, isolation forest trees tend to be rather large, and the contents on the nodes can be very long when using 'ndim>1' - if the idea is to get easily visualizable trees, one might want to use parameters like 'ndim=1', 'sample_size=256', 'max_depth=8'.

Value

An 'htmlwidget' object that contains the plot.


isotree documentation built on May 29, 2024, 11:24 a.m.