From 7558a9450785d49307b7c15f36ef69326ec4f966 Mon Sep 17 00:00:00 2001 From: El Potaeto Date: Tue, 30 Dec 2014 16:38:56 +0100 Subject: [PATCH] Update wlkthrough R demo code to include variable importance. --- R-package/demo/basic_walkthrough.R | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/R-package/demo/basic_walkthrough.R b/R-package/demo/basic_walkthrough.R index 59f5cd72e..7e6914b31 100644 --- a/R-package/demo/basic_walkthrough.R +++ b/R-package/demo/basic_walkthrough.R @@ -88,6 +88,9 @@ pred <- predict(bst, dtest) err <- as.numeric(sum(as.integer(pred > 0.5) != label))/length(label) print(paste("test-error=", err)) -# Finally, you can dump the tree you learned using xgb.dump into a text file -xgb.dump(bst, "dump.raw.txt") +# You can dump the tree you learned using xgb.dump into a text file +xgb.dump(bst, "dump.raw.txt", with.stats = T) +# Finally, you can check which features are the most important. +print("Most important features (look at column Gain):") +print(xgb.importance(feature_names = train$data@Dimnames[[2]], filename_dump = "dump.raw.txt"))