* [R] xgb.save must work when handle in nil but raw exists * [R] print.xgb.Booster should still print other info when handle is nil * [R] rename internal function xgb.Booster to xgb.Booster.handle to make its intent clear * [R] rename xgb.Booster.check to xgb.Booster.complete and make it visible; more docs * [R] storing evaluation_log should depend only on watchlist, not on verbose * [R] reduce the excessive chattiness of unit tests * [R] only disable some tests in windows when it's not 64-bit * [R] clean-up xgb.DMatrix * [R] test xgb.DMatrix loading from libsvm text file * [R] store feature_names in xgb.Booster, use them from utility functions * [R] remove non-functional co-occurence computation from xgb.importance * [R] verbose=0 is enough without a callback * [R] added forgotten xgb.Booster.complete.Rd; cran check fixes * [R] update installation instructions
67 lines
2.4 KiB
R
67 lines
2.4 KiB
R
% Generated by roxygen2: do not edit by hand
|
|
% Please edit documentation in R/xgb.importance.R
|
|
\name{xgb.importance}
|
|
\alias{xgb.importance}
|
|
\title{Importance of features in a model.}
|
|
\usage{
|
|
xgb.importance(feature_names = NULL, model = NULL, data = NULL,
|
|
label = NULL, target = NULL)
|
|
}
|
|
\arguments{
|
|
\item{feature_names}{character vector of feature names. If the model already
|
|
contains feature names, those would be used when \code{feature_names=NULL} (default value).
|
|
Non-null \code{feature_names} could be provided to override those in the model.}
|
|
|
|
\item{model}{object of class \code{xgb.Booster}.}
|
|
|
|
\item{data}{deprecated.}
|
|
|
|
\item{label}{deprecated.}
|
|
|
|
\item{target}{deprecated.}
|
|
}
|
|
\value{
|
|
For a tree model, a \code{data.table} with the following columns:
|
|
\itemize{
|
|
\item \code{Features} names of the features used in the model;
|
|
\item \code{Gain} represents fractional contribution of each feature to the model based on
|
|
the total gain of this feature's splits. Higher percentage means a more important
|
|
predictive feature.
|
|
\item \code{Cover} metric of the number of observation related to this feature;
|
|
\item \code{Frequency} percentage representing the relative number of times
|
|
a feature have been used in trees.
|
|
}
|
|
|
|
A linear model's importance \code{data.table} has only two columns:
|
|
\itemize{
|
|
\item \code{Features} names of the features used in the model;
|
|
\item \code{Weight} the linear coefficient of this feature.
|
|
}
|
|
|
|
If you don't provide or \code{model} doesn't have \code{feature_names},
|
|
index of the features will be used instead. Because the index is extracted from the model dump
|
|
(based on C++ code), it starts at 0 (as in C/C++ or Python) instead of 1 (usual in R).
|
|
}
|
|
\description{
|
|
Creates a \code{data.table} of feature importances in a model.
|
|
}
|
|
\details{
|
|
This function works for both linear and tree models.
|
|
|
|
For linear models, the importance is the absolute magnitude of linear coefficients.
|
|
For that reason, in order to obtain a meaningful ranking by importance for a linear model,
|
|
the features need to be on the same scale (which you also would want to do when using either
|
|
L1 or L2 regularization).
|
|
}
|
|
\examples{
|
|
|
|
data(agaricus.train, package='xgboost')
|
|
|
|
bst <- xgboost(data = agaricus.train$data, label = agaricus.train$label, max_depth = 2,
|
|
eta = 1, nthread = 2, nrounds = 2,objective = "binary:logistic")
|
|
|
|
xgb.importance(model = bst)
|
|
|
|
}
|
|
|