|
1 | 1 | #' Plot a boosted tree model |
2 | 2 | #' |
3 | | -#' Read a tree model text dump. |
4 | | -#' Plotting only works for boosted tree model (not linear model). |
| 3 | +#' Read a tree model text dump and plot the model. |
5 | 4 | #' |
6 | 5 | #' @importFrom data.table data.table |
7 | 6 | #' @importFrom data.table := |
8 | 7 | #' @importFrom magrittr %>% |
9 | | -#' @param 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}. |
| 8 | +#' @param feature_names names of each feature as a \code{character} vector. Can be extracted from a sparse matrix (see example). If model dump already contains feature names, this argument should be \code{NULL}. |
10 | 9 | #' @param model generated by the \code{xgb.train} function. Avoid the creation of a dump file. |
11 | 10 | #' @param n_first_tree limit the plot to the n first trees. If \code{NULL}, all trees of the model are plotted. Performance can be low for huge models. |
12 | 11 | #' @param plot.width the width of the diagram in pixels. |
|
19 | 18 | #' The content of each node is organised that way: |
20 | 19 | #' |
21 | 20 | #' \itemize{ |
22 | | -#' \item \code{feature} value ; |
23 | | -#' \item \code{cover}: the sum of second order gradient of training data classified to the leaf, if it is square loss, this simply corresponds to the number of instances in that branch. Deeper in the tree a node is, lower this metric will be ; |
| 21 | +#' \item \code{feature} value; |
| 22 | +#' \item \code{cover}: the sum of second order gradient of training data classified to the leaf, if it is square loss, this simply corresponds to the number of instances in that branch. Deeper in the tree a node is, lower this metric will be; |
24 | 23 | #' \item \code{gain}: metric the importance of the node in the model. |
25 | 24 | #' } |
26 | 25 | #' |
27 | | -#' Each branch finishes with a leaf. For each leaf, only the \code{cover} is indicated. |
28 | | -#' It uses \href{http://www.graphviz.org/}{GraphViz} library for that purpose. |
| 26 | +#' The function uses \href{http://www.graphviz.org/}{GraphViz} library for that purpose. |
29 | 27 | #' |
30 | 28 | #' @examples |
31 | 29 | #' data(agaricus.train, package='xgboost') |
32 | 30 | #' |
33 | | -#' #Both dataset are list with two items, a sparse matrix and labels |
34 | | -#' #(labels = outcome column which will be learned). |
35 | | -#' #Each column of the sparse Matrix is a feature in one hot encoding format. |
36 | | -#' |
37 | 31 | #' bst <- xgboost(data = agaricus.train$data, label = agaricus.train$label, max.depth = 2, |
38 | 32 | #' eta = 1, nthread = 2, nround = 2,objective = "binary:logistic") |
39 | 33 | #' |
40 | | -#' #agaricus.test$data@@Dimnames[[2]] represents the column names of the sparse matrix. |
| 34 | +#' # agaricus.train$data@@Dimnames[[2]] represents the column names of the sparse matrix. |
41 | 35 | #' xgb.plot.tree(feature_names = agaricus.train$data@@Dimnames[[2]], model = bst) |
42 | 36 | #' |
43 | 37 | #' @export |
|
0 commit comments