Isolation Forest
· β 3 min read · βοΈ Hoontaek Lee
knitr::opts_chunk$set(eval = TRUE, echo = TRUE, warning = FALSE)
References:
solitude: https://github.com/talegari/solitude isofor: https://campus.datacamp.com/courses/anomaly-detection-in-r/isolation-forest # install.packages("mvoutlier"))
# install.packages("remotes"))
# remotes::install_github("Zelazny7/isofor")
#import libraries
library(ggplot2)
library(ggpubr)
library(solitude) # hereafter, "sol"
library(isofor) # hereafter, "iso"
library(viridis)
packageVersion("solitude")
#create sample data
data("humus", package = "mvoutlier")
# 2-dimensional
columns_required <- c("Bi", "Cd")
humus2 <- humus[ , columns_required]
# multi-dimensional
columns_required_mul <- setdiff(colnames(humus)
, c("Cond", "ID", "XCOO", "YCOO", "LOI")
)
humus_mul <- humus[ , columns_required_mul]
str(humus2)
str(humus_mul)
#plot data
ggplot(humus2, aes(x = Bi, y = Cd)) + geom_point(shape = 1, alpha = 0.