knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "man/figures/README-",
  out.width = "100%"
)

LDATree LDATree website

CRAN status R-CMD-check CRAN Downloads

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

Overview

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

Installation

install.packages("LDATree")

You can install the development version of LDATree from GitHub with:

# install.packages("devtools")
devtools::install_github('Moran79/LDATree')

Basic Usage

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)

# Three types of individual plots
# 1. Scatter plot on first two LD scores
plot(fit, datX = datX, response = response, node = 1)

# 2. Density plot on the first LD score
plot(fit, datX = datX, response = response, node = 7)

# 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)

More examples can be found in the vignette.

References

Getting help

If you encounter a clear bug, please file an issue with a minimal reproducible example on GitHub



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