From 2154a160a37ec50edc099c9e00ddab4b42c38e43 Mon Sep 17 00:00:00 2001 From: El Potaeto Date: Sun, 28 Dec 2014 11:18:26 +0100 Subject: [PATCH] refactoring of validation to improve source code readability. --- R-package/R/xgb.importance.R | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/R-package/R/xgb.importance.R b/R-package/R/xgb.importance.R index 690795ff4..88af8387a 100644 --- a/R-package/R/xgb.importance.R +++ b/R-package/R/xgb.importance.R @@ -41,14 +41,14 @@ treeDump <- function(feature_names, text){ m <- regexec("\\[f.*\\]", line) p <- regmatches(line, m) if (length(p[[1]]) > 0) { - splits <- as.numeric(strsplit(sub("\\]", "", sub("\\[f", "", p[[1]])), "<")[[1]]) + splits <- sub("\\]", "", sub("\\[f", "", p[[1]])) %>% strsplit("<")[[1]] %>% as.numeric result <- c(result, feature_names[splits[1]+ 1]) } } - #1. Reduce, 2. %, 3. remove temp col, 4. reorder - bigger top + #1. Reduce, 2. %, 3. reorder - bigger top, 4. remove temp col data.table(Feature = result)[,.N, by = Feature][, Weight:= N /sum(N)][order(-rank(Weight))][,-2,with=F] } linearDump <- function(feature_names, text){ - which(text == "weight:") %>% {a=.+1;text[a:length(text)]} %>% as.numeric %>% data.table(Feature = feature_names, Weight = .) + which(text == "weight:") %>% {a=.+1; text[a:length(text)]} %>% as.numeric %>% data.table(Feature = feature_names, Weight = .) } \ No newline at end of file