34 lines
1.1 KiB
R
34 lines
1.1 KiB
R
% Generated by roxygen2 (4.1.0): do not edit by hand
|
|
% Please edit documentation in R/xgb.importance.R
|
|
\name{xgb.importance}
|
|
\alias{xgb.importance}
|
|
\title{Show importance of features in a model}
|
|
\usage{
|
|
xgb.importance(feature_names, filename_dump)
|
|
}
|
|
\arguments{
|
|
\item{feature_names}{names of each feature as a character vector. Can be extracted from a sparse matrix.}
|
|
|
|
\item{filename_dump}{the name of the text file.}
|
|
}
|
|
\description{
|
|
Read a xgboost model in text file format. Return a data.table of the features with their weight.
|
|
}
|
|
\examples{
|
|
data(agaricus.train, package='xgboost')
|
|
data(agaricus.test, package='xgboost')
|
|
|
|
#Both dataset are list with two items, a sparse matrix and labels (outcome column which will be learned).
|
|
#Each column of the sparse Matrix is a feature in one hot encoding format.
|
|
train <- agaricus.train
|
|
test <- agaricus.test
|
|
|
|
bst <- xgboost(data = train$data, label = train$label, max.depth = 2,
|
|
eta = 1, nround = 2,objective = "binary:logistic")
|
|
xgb.dump(bst, 'xgb.model.dump')
|
|
|
|
#agaricus.test$data@Dimnames[[2]] represents the column name of the sparse matrix.
|
|
xgb.importance(agaricus.test$data@Dimnames[[2]], 'xgb.model.dump')
|
|
}
|
|
|