From 1eeac36aed577fd2f9edf7ed0d4702e3fc41cf63 Mon Sep 17 00:00:00 2001 From: Chris Kennedy Date: Thu, 25 Jul 2024 11:41:15 -0400 Subject: [PATCH 1/3] unify_ranger.R: fix for probability forests --- R/unify_ranger.R | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/R/unify_ranger.R b/R/unify_ranger.R index 45c5380..5432833 100644 --- a/R/unify_ranger.R +++ b/R/unify_ranger.R @@ -41,6 +41,10 @@ ranger.unify <- function(rf_model, data) { n <- rf_model$num.trees x <- lapply(1:n, function(tree) { tree_data <- data.table::as.data.table(ranger::treeInfo(rf_model, tree = tree)) + # Fix for probability forests + if (rf$treetype == "Probability estimation") { + setnames(tree_data, "pred.1", "prediction") + } tree_data[, c("nodeID", "leftChild", "rightChild", "splitvarName", "splitval", "prediction")] }) return(ranger_unify.common(x = x, n = n, data = data, feature_names = rf_model$forest$independent.variable.names)) From ceaf107db5558ae770772392b76cc4114c5e3e33 Mon Sep 17 00:00:00 2001 From: Chris Kennedy Date: Thu, 25 Jul 2024 11:42:12 -0400 Subject: [PATCH 2/3] Update unify_ranger.R --- R/unify_ranger.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/unify_ranger.R b/R/unify_ranger.R index 5432833..7ff8fb8 100644 --- a/R/unify_ranger.R +++ b/R/unify_ranger.R @@ -43,7 +43,7 @@ ranger.unify <- function(rf_model, data) { tree_data <- data.table::as.data.table(ranger::treeInfo(rf_model, tree = tree)) # Fix for probability forests if (rf$treetype == "Probability estimation") { - setnames(tree_data, "pred.1", "prediction") + data.table::setnames(tree_data, "pred.1", "prediction") } tree_data[, c("nodeID", "leftChild", "rightChild", "splitvarName", "splitval", "prediction")] }) From 9944bcbb3abc4109a13c06b0bb94b6d66c2e4424 Mon Sep 17 00:00:00 2001 From: Chris Kennedy Date: Thu, 25 Jul 2024 11:58:50 -0400 Subject: [PATCH 3/3] Update unify_ranger.R --- R/unify_ranger.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/unify_ranger.R b/R/unify_ranger.R index 7ff8fb8..a3d04a4 100644 --- a/R/unify_ranger.R +++ b/R/unify_ranger.R @@ -42,7 +42,7 @@ ranger.unify <- function(rf_model, data) { x <- lapply(1:n, function(tree) { tree_data <- data.table::as.data.table(ranger::treeInfo(rf_model, tree = tree)) # Fix for probability forests - if (rf$treetype == "Probability estimation") { + if (rf_model$treetype == "Probability estimation") { data.table::setnames(tree_data, "pred.1", "prediction") } tree_data[, c("nodeID", "leftChild", "rightChild", "splitvarName", "splitval", "prediction")]