# NOT RUN {
data("humus", package = "mvoutlier")
columns_required = setdiff(colnames(humus)
, c("Cond", "ID", "XCOO", "YCOO", "LOI")
)
humus2 = humus[ , columns_required]
str(humus2)
set.seed(1)
index = sample(ceiling(nrow(humus2) * 0.5))
# initiate an isolation forest
iso = isolationForest$new(sample_size = length(index))
iso$fit(dataset = humus2[index, ])
iso$predict(humus2[index, ]) # scores for train data
iso$predict(humus2[-index, ]) # scores for new data (50% sample)
# }
Run the code above in your browser using DataLab