knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)
library(LDATree)

LDATree is an R modeling package for fitting classification trees with oblique splits.

Why use the LDATree package?

Compared to other similar trees, LDATree distinguishes itself in the following ways:

Basic Usage of LDATree

We offer two main tree types in the LDATree package: LDATree and FoLDTree. For the splitting rule and node model, LDATree uses ULDA, while FoLDTree uses forward ULDA.

To build an LDATree (or FoLDTree):

library(LDATree)
set.seed(443)
diamonds <- as.data.frame(ggplot2::diamonds)[sample(53940, 2000),]
datX <- diamonds[, -2]
response <- diamonds[, 2] # we try to predict "cut"
fit <- Treee(datX = datX, response = response, verbose = FALSE) # by default, it is a pre-stopping FoLDTree
# fit <- Treee(datX = datX, response = response, verbose = FALSE, ldaType = "all", pruneMethod = "post") # if you want to fit a post-pruned LDATree.

To plot the LDATree (or FoLDTree):

# View the overall tree.
plot(fit)
knitr::include_graphics("README-plot1-1.png")
# Three types of individual plots
# 1. Scatter plot on first two LD scores
plot(fit, datX = datX, response = response, node = 1)
knitr::include_graphics("README-plot2-1.png")
# 2. Density plot on the first LD score
plot(fit, datX = datX, response = response, node = 7)
knitr::include_graphics("README-plot2-2.png")
# 3. A message
plot(fit, datX = datX, response = response, node = 2)

To make predictions:

# Prediction only.
predictions <- predict(fit, datX)
head(predictions)
# A more informative prediction
predictions <- predict(fit, datX, type = "all")
head(predictions)

Additional Features

References



Moran79/LDATree documentation built on Nov. 4, 2024, 12:06 p.m.