distanceRandomForest {CaseBasedReasoning}  R Documentation 
Distance calculation based on RandomForest Proximity or Depth
distanceRandomForest(
x,
y = NULL,
rfObject,
method = "Proximity",
threads = NULL
)
x 
a data.frame 
y 
a second data.frame 
rfObject 

method 
distance calculation method, Proximity (Default) or Depth. 
threads 
number of threads to use 
a dist
or a matrix object with pairwise distance of
observations in x vs y (if not null)
library(ranger)
# proximity pairwise distances
rf.fit < ranger(Species ~ ., data = iris, num.trees = 500, write.forest = TRUE)
distanceRandomForest(x = iris[, 5], rfObject = rf.fit, method = "Proximity", threads = 1)
# depth distance for train versus test subset
set.seed(1234L)
learn < sample(1:150, 100)
test < (1:150)[learn]
rf.fit < ranger(Species ~ ., data = iris[learn, ], num.trees = 500, write.forest = TRUE)
distanceRandomForest(x = iris[learn, 5], y = iris[test, 5], rfObject = rf.fit, method = "Depth")