compute_lp-forestry: compute lp distances

Description Usage Arguments Value Examples

Description

Return lp distances of selected test observations.

Usage

1
compute_lp(object, feature.new, feature, p)

Arguments

object

A trained model object of class "forestry".

feature.new

A data frame of testing predictors.

feature

A string denoting the dimension for computing lp distances.

p

A positive real number determining the norm p-norm used.

Value

A vector lp distances.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
# Set seed for reproductivity
set.seed(292313)

# Use Iris Data
test_idx <- sample(nrow(iris), 11)
x_train <- iris[-test_idx, -1]
y_train <- iris[-test_idx, 1]
x_test <- iris[test_idx, -1]

rf <- forestry(x = x_train, y = y_train)
predict(rf, x_test)

# Compute the l2 distances in the "Petal.Length" dimension
distances_2 <- compute_lp(object = rf,
                          feature.new = x_test,
                          feature = "Petal.Length",
                          p = 2)

soerenkuenzel/forestry documentation built on April 25, 2021, 10:02 a.m.