# NOT RUN {
# iris example
require(HPLB)
require(ranger)
# training a multi-class classifier on iris and getting tv lower bounds between classes
data("iris")
ind.train <- sample(1:nrow(iris), size = nrow(iris)/2, replace = FALSE)
rf <- ranger(Species~., data = iris[ind.train, ], probability = TRUE)
preds <- predict(rf, iris[-ind.train,])$predictions
# creating the ordering array based on prediction differences
ar <- array(dim = c(3, 3, nrow(preds)))
for (i in 1:3) {
for (j in 1:3) {
ar[i,j,] <- preds[,j] - preds[,i]
}
}
# encoding the class response
y <- factor(iris$Species)
levels(y) <- c(0,1,2)
y <- as.numeric(y)-1
# getting the lower bound matrix
tvhat.iris <- HPLBmatrix(labels = y[-ind.train], ordering.array = ar)
tvhat.iris
# }
Run the code above in your browser using DataLab