% Generated by roxygen2: do not edit by hand % Please edit documentation in R/xgb.plot.importance.R \name{xgb.plot.importance} \alias{xgb.plot.importance} \title{Plot feature importance bar graph} \usage{ xgb.plot.importance(importance_matrix = NULL, n_clusters = c(1:10), ...) } \arguments{ \item{importance_matrix}{a \code{data.table} returned by the \code{xgb.importance} function.} \item{n_clusters}{a \code{numeric} vector containing the min and the max range of the possible number of clusters of bars.} \item{...}{currently not used} } \value{ A \code{ggplot2} bar graph representing each feature by a horizontal bar. Longer is the bar, more important is the feature. Features are classified by importance and clustered by importance. The group is represented through the color of the bar. } \description{ Read a data.table containing feature importance details and plot it (for both GLM and Trees). } \details{ The purpose of this function is to easily represent the importance of each feature of a model. The function returns a ggplot graph, therefore each of its characteristic can be overriden (to customize it). In particular you may want to override the title of the graph. To do so, add \code{+ ggtitle("A GRAPH NAME")} next to the value returned by this function. } \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. bst <- xgboost(data = agaricus.train$data, label = agaricus.train$label, max_depth = 2, eta = 1, nthread = 2, nrounds = 2, objective = "binary:logistic") importance_matrix <- xgb.importance(colnames(agaricus.train$data), model = bst) xgb.plot.importance(importance_matrix) }