Learn R Programming

CaseBasedReasoning (version 0.1)

distanceRandomForest: Distance calculation based on RandomForest Proximity or Depth

Description

Distance calculation based on RandomForest Proximity or Depth

Usage

distanceRandomForest(x, y = NULL, rfObject, method = "Proximity",
  threads = NULL)

Arguments

x

a data.frame

y

a second data.frame

rfObject

ranger object

method

distance calculation method

threads

number of threads to use

Value

a dist or a matrix object with pairwise distance of observations in x vs y (if not null)

Examples

Run this code
# NOT RUN {
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")

# }

Run the code above in your browser using DataLab