From 6e9017c47439d4aa6e855f5c6fe2ded93c077db9 Mon Sep 17 00:00:00 2001 From: pommedeterresautee Date: Tue, 24 Nov 2015 13:12:35 +0100 Subject: [PATCH] fix for Travis --- R-package/DESCRIPTION | 5 ++- R-package/demo/xgb.plot.multi.tree.R | 64 ---------------------------- 2 files changed, 3 insertions(+), 66 deletions(-) delete mode 100644 R-package/demo/xgb.plot.multi.tree.R diff --git a/R-package/DESCRIPTION b/R-package/DESCRIPTION index f36e34274..6594954f3 100644 --- a/R-package/DESCRIPTION +++ b/R-package/DESCRIPTION @@ -20,11 +20,12 @@ BugReports: https://github.com/dmlc/xgboost/issues VignetteBuilder: knitr Suggests: knitr, - ggplot2 (>= 1.0.0), + ggplot2 (>= 1.0.1), DiagrammeR (>= 0.8.1), Ckmeans.1d.dp (>= 3.3.1), vcd (>= 1.3), - testthat + testthat, + igraph (>= 1.0.1) Depends: R (>= 2.10) Imports: diff --git a/R-package/demo/xgb.plot.multi.tree.R b/R-package/demo/xgb.plot.multi.tree.R deleted file mode 100644 index feb7e667e..000000000 --- a/R-package/demo/xgb.plot.multi.tree.R +++ /dev/null @@ -1,64 +0,0 @@ -library(stringr) -library(data.table) -library(xgboost) - - -data(agaricus.train, package='xgboost') - -#Both dataset are list with two items, a sparse matrix and labels -#(labels = outcome column which will be learned). -#Each column of the sparse Matrix is a feature in one hot encoding format. -train <- agaricus.train - -bst <- xgboost(data = train$data, label = train$label, max.depth = 2, - eta = 1, nthread = 2, nround = 4, objective = "binary:logistic") - -#agaricus.test$data@Dimnames[[2]] represents the column names of the sparse matrix. -tree.matrix <- xgb.model.dt.tree(agaricus.train$data@Dimnames[[2]], model = bst) - - -# first number of the path represents the tree, then the following numbers are related to the path to follow - -# root init -root.nodes <- tree.matrix[str_detect(ID, "\\d+-0"), ID] -tree.matrix[ID == root.nodes, Abs.Position:=root.nodes] - -precedent.nodes <- root.nodes - -while(tree.matrix[,sum(is.na(Abs.Position))] > 0) { - yes.row.nodes <- tree.matrix[Abs.Position %in% precedent.nodes & !is.na(Yes)] - no.row.nodes <- tree.matrix[Abs.Position %in% precedent.nodes & !is.na(No)] - yes.nodes.abs.pos <- yes.row.nodes[, Abs.Position] %>% paste0("_0") - no.nodes.abs.pos <- no.row.nodes[, Abs.Position] %>% paste0("_1") - - tree.matrix[ID == yes.row.nodes[, Yes], Abs.Position := yes.nodes.abs.pos] - tree.matrix[ID == no.row.nodes[, No], Abs.Position := no.nodes.abs.pos] - precedent.nodes <- c(yes.nodes.abs.pos, no.nodes.abs.pos) -} - -tree.matrix[!is.na(Yes),Yes:= paste0(Abs.Position, "_0")] -tree.matrix[!is.na(No),No:= paste0(Abs.Position, "_1")] -tree.matrix[,ID:= Abs.Position] - -tree.matrix[,Abs.Position:=substr(Abs.Position, nchar(Tree)+2, nchar(Abs.Position))] -keepN <- 3 -tree.matrix <- tree.matrix[,sum(Quality),by = .(Abs.Position, Feature)][order(-V1)][,.(paste0(Feature[1:min(length(Feature), keepN)], " (", V1[1:min(length(V1), keepN)], ")") %>% paste0(collapse = "\n")), by=Abs.Position] - -tree.matrix[Feature!="Leaf" ,yesPath:= paste(ID,"(", Feature, "
Cover: ", Cover, "
Gain: ", Quality, ")-->|< ", Split, "|", Yes, ">", Yes.Feature, "]", sep = "")] - -tree.matrix[Feature!="Leaf" ,noPath:= paste(ID,"(", Feature, ")-->|>= ", Split, "|", No, ">", No.Feature, "]", sep = "")] - -tree.matrix[, Yes:= Abs.Position %>% paste0("_0")][, No:= Abs.Position %>% paste0("_1")] - -CSSstyle <- "classDef greenNode fill:#A2EB86, stroke:#04C4AB, stroke-width:2px\nclassDef redNode fill:#FFA070, stroke:#FF5E5E, stroke-width:2px" - - -yes <- tree.matrix[Feature!="Leaf", c(Yes)] %>% paste(collapse = ",") %>% paste("class ", ., " greenNode", sep = "") - -no <- tree.matrix[Feature!="Leaf", c(No)] %>% paste(collapse = ",") %>% paste("class ", ., " redNode", sep = "") - -path <- tree.matrix[Feature!="Leaf", c(yesPath, noPath)] %>% .[order(.)] %>% paste(sep = "", collapse = "\n") %>% paste("graph LR", .,collapse = "", sep = "\n") %>% paste(CSSstyle, yes, no, sep = "\n") -DiagrammeR::mermaid(path) - -# path <- "graph LR;0-0-0(spore-print-color=green)-->|>= 2.00001|0-0-0-1>Leaf" -# setnames(tree.matrix, old = c("ID", "Yes", "No"), c("nodes", "edge_from", "edge_to"))