Skip to content

Commit

Permalink
fctrs as numeric for resampling
Browse files Browse the repository at this point in the history
  • Loading branch information
dswatson committed Nov 8, 2023
1 parent a6498f4 commit ffa47c6
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion R/adversarial_rf.R
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,12 @@ adversarial_rf <- function(
nodeIDs <- stats::predict(rf0, x_real, type = 'terminalNodes')$predictions
tmp <- data.table('tree' = rep(seq_len(num_trees), each = n),
'leaf' = as.vector(nodeIDs))
x_real_dt <- rbindlist(lapply(seq_len(num_trees), function(b) {
x_real_dt <- do.call(rbind, lapply(seq_len(num_trees), function(b) {
cbind(x_real, tmp[tree == b])
}))
x_real_dt[, factor_cols] <- setDF(
lapply(x_real_dt[, factor_cols, drop = FALSE], as.numeric)
)
tmp <- tmp[sample(.N, n, replace = TRUE)]
tmp <- unique(tmp[, cnt := .N, by = .(tree, leaf)])
draw_from <- merge(tmp, x_real_dt, by = c('tree', 'leaf'),
Expand Down

0 comments on commit ffa47c6

Please sign in to comment.