From 68290546ca4fdda3f240ebb6529805924a64ec03 Mon Sep 17 00:00:00 2001 From: El Potaeto Date: Thu, 5 Feb 2015 09:53:21 +0100 Subject: [PATCH] simplidied included column computation --- R-package/R/xgb.model.dt.tree.R | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/R-package/R/xgb.model.dt.tree.R b/R-package/R/xgb.model.dt.tree.R index acdcdbdfa..c88c16989 100644 --- a/R-package/R/xgb.model.dt.tree.R +++ b/R-package/R/xgb.model.dt.tree.R @@ -129,8 +129,8 @@ xgb.model.dt.tree <- function(feature_names = NULL, filename_dump = NULL, model qualityLeaf <- extract(leaf, "leaf=\\-*\\d*\\.*\\d*") coverBranch <- extract(branch, "cover=\\d*\\.*\\d*") coverLeaf <- extract(leaf, "cover=\\d*\\.*\\d*") - dt <- data.table(ID = c(idBranch, idLeaf), Feature = c(featureBranch, featureLeaf), Split = c(splitBranch, splitLeaf), Yes = c(yesBranch, yesLeaf), No = c(noBranch, noLeaf), Missing = c(missingBranch, missingLeaf), Quality = c(qualityBranch, qualityLeaf), Cover = c(coverBranch, coverLeaf))[order(ID)][,Tree:=treeID] - + dt <- data.table(ID = c(idBranch, idLeaf), Feature = c(featureBranch, featureLeaf), Split = c(splitBranch, splitLeaf), Yes = c(yesBranch, yesLeaf), No = c(noBranch, noLeaf), Missing = c(missingBranch, missingLeaf), Quality = c(qualityBranch, qualityLeaf), Cover = c(coverBranch, coverLeaf))[order(ID)][,Tree:=treeID][,"Included":=F][ID == yesBranch, Included:=T][1, Included:=T] + allTrees <- rbindlist(list(allTrees, dt), use.names = T, fill = F) } @@ -161,9 +161,7 @@ xgb.model.dt.tree <- function(feature_names = NULL, filename_dump = NULL, model set(allTrees, i = which(allTrees[,Feature]!= "Leaf"), j = "No.Quality", value = allTrees[ID == no,Quality]) - - allTrees[,"Included":=F][ID == allTrees[!is.na(Yes), Yes], Included:=T][str_detect(ID, "-0$"), Included:=T] - + allTrees }