From 412a6e10859770d68a3ec831dbffd0fd75cfcdbb Mon Sep 17 00:00:00 2001 From: El Potaeto Date: Tue, 17 Feb 2015 23:30:36 +0100 Subject: [PATCH] Add comments --- R-package/R/xgb.importance.R | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/R-package/R/xgb.importance.R b/R-package/R/xgb.importance.R index c53d9e3e8..07fbfded3 100644 --- a/R-package/R/xgb.importance.R +++ b/R-package/R/xgb.importance.R @@ -94,15 +94,19 @@ xgb.importance <- function(feature_names = NULL, filename_dump = NULL, model = N result <- treeDump(feature_names, text = text, keepDetail = !is.null(data)) # Co-occurence computation - if(!is.null(data) & !is.null(label) & nrow(result) > 0) { + if(!is.null(data) & !is.null(label) & nrow(result) > 0) { + # Apply split a <- data[, result[,Feature],drop=FALSE] < as.numeric(result[,Split]) + # Take care of missing column b <- data[, result[No == Missing,Feature],drop=FALSE] != 0 + # Do nothing if missing should be included in Yes c <- data[, result[No != Missing,Feature],drop=FALSE] + # Bind the two previous Matrix and reorder columns d <- cBind(b,c) %>% .[,result[,Feature]] apply(a & d, 2, . %>% target %>% sum) -> vec - result <- result[, "RealCover":= as.numeric(vec), with = F][, "RealCover %" := RealCover / sum(label)] + result <- result[, "RealCover":= as.numeric(vec), with = F][, "RealCover %" := RealCover / sum(label)][,`:=`(No = NULL, Missing = NULL)] } } result