From 3d068b4e1ade70768f223d5993835932cd1091bb Mon Sep 17 00:00:00 2001 From: El Potaeto Date: Mon, 5 Jan 2015 19:26:09 +0100 Subject: [PATCH] new documentation new import --- R-package/NAMESPACE | 4 ++++ R-package/man/xgb.plot.tree.Rd | 40 ++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 R-package/man/xgb.plot.tree.Rd diff --git a/R-package/NAMESPACE b/R-package/NAMESPACE index 6e74d9ac2..a20057e25 100644 --- a/R-package/NAMESPACE +++ b/R-package/NAMESPACE @@ -9,6 +9,7 @@ export(xgb.cv) export(xgb.dump) export(xgb.importance) export(xgb.load) +export(xgb.plot.tree) export(xgb.save) export(xgb.train) export(xgboost) @@ -16,13 +17,16 @@ exportMethods(predict) import(methods) importClassesFrom(Matrix,dgCMatrix) importClassesFrom(Matrix,dgeMatrix) +importFrom(DiagrammeR,DiagrammeR) importFrom(data.table,":=") importFrom(data.table,as.data.table) importFrom(data.table,data.table) importFrom(data.table,rbindlist) +importFrom(data.table,set) importFrom(magrittr,"%>%") importFrom(stringr,str_extract) importFrom(stringr,str_extract_all) importFrom(stringr,str_match) importFrom(stringr,str_replace) importFrom(stringr,str_split) +importFrom(stringr,str_trim) diff --git a/R-package/man/xgb.plot.tree.Rd b/R-package/man/xgb.plot.tree.Rd new file mode 100644 index 000000000..08f8b9c94 --- /dev/null +++ b/R-package/man/xgb.plot.tree.Rd @@ -0,0 +1,40 @@ +% Generated by roxygen2 (4.1.0): do not edit by hand +% Please edit documentation in R/xgb.plot.tree.R +\name{xgb.plot.tree} +\alias{xgb.plot.tree} +\title{Plot a boosted tree model} +\usage{ +xgb.plot.tree(feature_names = NULL, filename_dump = NULL) +} +\arguments{ +\item{feature_names}{names of each feature as a character vector. Can be extracted from a sparse matrix (see example). If model dump already contains feature names, this argument should be \code{NULL}.} + +\item{filename_dump}{the path to the text file storing the model. Model dump must include the gain per feature and per tree (\code{with.stats = T} in function \code{xgb.dump}).} +} +\value{ +A \code{data.table} of the features used in the model with their average gain (and their weight for boosted tree model) in the model. +} +\description{ +Read a xgboost model text dump. +Only works for boosted tree model (not linear model). +} +\details{ +This is the function to plot the trees growned. +It uses Mermaid JS library for that purpose. +Performance can be low for huge models. +} +\examples{ +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, nround = 2,objective = "binary:logistic") +xgb.dump(bst, 'xgb.model.dump', with.stats = T) + +#agaricus.test$data@Dimnames[[2]] represents the column names of the sparse matrix. +xgb.plot.tree(agaricus.train$data@Dimnames[[2]], 'xgb.model.dump') +} +