From d441a9d382ffecfe04e6c004d0bc1848e8a48f16 Mon Sep 17 00:00:00 2001 From: El Potaeto Date: Sun, 11 Jan 2015 23:37:02 +0100 Subject: [PATCH 1/2] avoid error when a tree is just made of one leaf --- R-package/R/xgb.model.dt.tree.R | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/R-package/R/xgb.model.dt.tree.R b/R-package/R/xgb.model.dt.tree.R index 5ad6c6b3d..3cabcf1a9 100644 --- a/R-package/R/xgb.model.dt.tree.R +++ b/R-package/R/xgb.model.dt.tree.R @@ -99,6 +99,9 @@ xgb.model.dt.tree <- function(feature_names = NULL, filename_dump = NULL, model tree <- text[(position[i]+1):(position[i+1]-1)] + # avoid tree made of a leaf only (no split) + if(length(tree) <2) break + treeID <- i-1 notLeaf <- str_match(tree, "leaf") %>% is.na @@ -129,7 +132,7 @@ xgb.model.dt.tree <- function(feature_names = NULL, filename_dump = NULL, model } yes <- allTrees[!is.na(Yes),Yes] - + set(allTrees, i = which(allTrees[,Feature]!= "Leaf"), j = "Yes.Feature", value = allTrees[ID == yes,Feature]) From 48c1911bc41505b2feeda438726aa8fd56e9e754 Mon Sep 17 00:00:00 2001 From: El Potaeto Date: Sun, 11 Jan 2015 23:39:24 +0100 Subject: [PATCH 2/2] fix error --- R-package/R/xgb.model.dt.tree.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R-package/R/xgb.model.dt.tree.R b/R-package/R/xgb.model.dt.tree.R index 3cabcf1a9..87b9f3a99 100644 --- a/R-package/R/xgb.model.dt.tree.R +++ b/R-package/R/xgb.model.dt.tree.R @@ -100,7 +100,7 @@ xgb.model.dt.tree <- function(feature_names = NULL, filename_dump = NULL, model tree <- text[(position[i]+1):(position[i+1]-1)] # avoid tree made of a leaf only (no split) - if(length(tree) <2) break + if(length(tree) <2) next treeID <- i-1