MyNixOS website logo
Description

Build Decision Trees with Optimal Multivariate Splits.

Functions for training an optimal decision tree classifier, making predictions and generating latex code for plotting. Works for two-class and multi-class classification problems. The algorithm seeks the optimal Boolean rule consisting of multiple variables to split a node, resulting in shorter trees. Use bsnsing() to build a tree, predict() to make predictions and plot() to plot the tree into latex and PDF. See Yanchao Liu (2022) <arXiv:2205.15263> for technical details. Source code and more data sets are at <https://github.com/profyliu/bsnsing/>.

bsnsing

Learn a Classification Tree using Boolean Sensing

Other tree-building methods, such as C50, tree, ctree and rpart available in R, utilize only a single variable in each split, which limits the expressiveness and in some cases the predictive accuracy of the tree model.

In bsnsing, an optimization problem is solved at each node to identify the best combination of features by which to split the node. Currently, supported MIP solvers include cplex, gurobi, lpSolve, an implicit enumeration (ENUM) algorithm and a greedy heuristic.

The bsnsing package does not depend on them to work out-of-the-box, but

To use the CPLEX solver, licensed CPLEX software and the R package cplexAPI must be installed.

To use the Gurobi solver, licensed Gurobi software and the R package gurobi must be installed.

The lpSolve package should be automatically installed along with bsnsing. If not, install it by install.packages('lpSolve').

Install bsnsing from Github

Windows users need to install Rtools (https://cran.r-project.org/bin/windows/Rtools/) before installing the devtools package.

install.packages('devtools')

library(devtools)

install_github("profyliu/bsnsing")

library(bsnsing)

Install bsnsing from source

Download this repository, and in R run:

install.packages(path_to_file, repos = NULL, type="source")

Build the bslearn.so / bslearn.dylib / bslearn.dll

On windows:

C:\rtools40\mingw64\bin\gcc -I"C:\Program Files\R\R-4.1.2\include" -fpic -c "C:...\bsnsing\C\bslearn.c"

C:\rtools40\mingw64\bin\gcc -I"C:\Program Files\R\R-4.1.2\include" -shared bslearn.o -o bslearn.dll

On Mac:

Go to the bsnsing/C folder, modify include path in the Makefile and run

make

to generate the bslearn.dylib file. On Linux:

Follow a similar procedure as on Mac, to generate the bslearn.so file.

Finally, copy & paste the dynamic library file (bslearn.dll on Windows, bslearn.dylib on Mac or bslearn.so on Linux) to the working directory of R in which bsnsing is run.

Note that the dynamic library file is not required to run bsnsing, but having it can boost bsnsing's speed by up to two orders of magnitude.

Usage Examples

n <- nrow(GlaucomaMVF)

set.seed(2018)

train_index <- sample(1:n, round(0.5 * n))

test_index <- setdiff(1:n, train_index)

Out-of-the-box run

bs <- bsnsing(Class ~ ., data = GlaucomaMVF, subset = train_index)

summary(bs)

Predict and display confusion matrix

pred <- predict(bs, GlaucomaMVF[test_index, ], type = 'class')

table(pred, actual = GlaucomaMVF[test_index, 'Class'])

Customize parameters

bs <- bsnsing(Class ~ ., data = GlaucomaMVF, subset = train_index, opt.model = 'error', opt.solver = 'gurobi')

To learn more about control parameters

?bscontrol

To display the current and default parameter values

bscontrol()

Multi-class classification

n <- nrow(iris)

set.seed(2018)

train_index <- sample(1:n, round(0.5 * n))

test_index <- setdiff(1:n, train_index)

bs <- bsnsing(Species ~ ., data = iris, subset = train_index)

summary(bs[[1]]) # display the first tree

summary(bs[[2]]) # display the second tree

summary(bs[[3]]) # display the third tree

table(pred = predict(bs, iris[test_index, ], type = 'class'), actual = iris[test_index, 'Species']) # Confusion matrix on the test set

Visualize the bsnsing tree

Use the plot function to generate a PDF plot as well as the latex code. For example,

plot(bs)

or

plot(bs, file = 'a.pdf')

Metadata

Version

1.0.1

License

Unknown

Platforms (77)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-freebsd
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64-windows
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows