Skip to content

Commit

Permalink
colnames fix
Browse files Browse the repository at this point in the history
  • Loading branch information
dswatson committed Aug 30, 2023
1 parent eabdd5e commit ab69529
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions R/forde.R
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,10 @@ forde <- function(
x <- as.data.frame(x)
n <- nrow(x)
d <- ncol(x)
factor_cols <- sapply(x, is.factor)
colnames_x <- colnames(x)
classes <- sapply(x, class)
x <- suppressWarnings(prep_x(x))
factor_cols <- sapply(x, is.factor)

# Compute leaf bounds and coverage
num_trees <- arf$num.trees
Expand Down Expand Up @@ -150,22 +150,21 @@ forde <- function(
}
}
leaves <- which(arf$forest$child.nodeIDs[[tree]][[1]] == 0L)
colnames(lb) <- arf$forest$independent.variable.names
colnames(ub) <- arf$forest$independent.variable.names
colnames(lb) <- colnames(ub) <- colnames_x
merge(melt(data.table(tree = tree, leaf = leaves, lb[leaves, ]),
id.vars = c('tree', 'leaf'), value.name = 'min'),
melt(data.table(tree = tree, leaf = leaves, ub[leaves, ]),
id.vars = c('tree', 'leaf'), value.name = 'max'),
by = c('tree', 'leaf', 'variable'), sort = FALSE)
}
if (isTRUE(parallel)) {
bnds <- foreach(tree = 1:num_trees, .combine = rbind) %dopar% bnd_fn(tree)
bnds <- foreach(tree = seq_len(num_trees), .combine = rbind) %dopar% bnd_fn(tree)
} else {
bnds <- foreach(tree = 1:num_trees, .combine = rbind) %do% bnd_fn(tree)
bnds <- foreach(tree = seq_len(num_trees), .combine = rbind) %do% bnd_fn(tree)
}
# Use only OOB data?
if (isTRUE(oob)) {
inbag <- (do.call(cbind, arf$inbag.counts) > 0L)[1:(arf$num.samples/2), ]
inbag <- (do.call(cbind, arf$inbag.counts) > 0L)[1:(arf$num.samples / 2), ]
pred[inbag] <- NA_integer_
bnds[, n_oob := sum(!is.na(pred[, tree])), by = tree]
bnds[, cvg := sum(pred[, tree] == leaf, na.rm = TRUE) / n_oob, by = .(tree, leaf)]
Expand Down

0 comments on commit ab69529

Please sign in to comment.