% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/vimp.R
\name{vimp}
\alias{vimp}
\title{Variable Importance}
\usage{
vimp(fit, data, type = NULL)
}
\arguments{
\item{fit}{An e2tree object.}

\item{data}{A data frame containing the variables in the model.}

\item{type}{Character string: \code{"classification"} or \code{"regression"}.
If \code{NULL} (default), the type is automatically detected from the
e2tree object.}
}
\value{
A list containing:
\describe{
\item{vimp}{A data frame with variable importance metrics.}
\item{g_imp}{A ggplot bar chart of Mean Impurity Decrease.}
\item{g_acc}{(Classification only) A ggplot bar chart of Mean Accuracy Decrease.}
}
}
\description{
Computes variable importance for an E2Tree model based on mean
impurity decrease and (for classification) mean accuracy decrease.
}
\examples{
\donttest{
## Classification:
data(iris)

# Create training and validation set:
smp_size <- floor(0.75 * nrow(iris))
train_ind <- sample(seq_len(nrow(iris)), size = smp_size)
training <- iris[train_ind, ]

# Perform training:
ensemble <- randomForest::randomForest(Species ~ ., data=training,
importance=TRUE, proximity=TRUE)

D <- createDisMatrix(ensemble, data=training, label = "Species",
                             parallel = list(active=FALSE, no_cores = 1))

setting=list(impTotal=0.1, maxDec=0.01, n=2, level=5)
tree <- e2tree(Species ~ ., training, D, ensemble, setting)

vi <- vimp(tree, training)
vi$vimp
vi$g_imp


## Regression
data("mtcars")

# Create training and validation set:
smp_size <- floor(0.75 * nrow(mtcars))
train_ind <- sample(seq_len(nrow(mtcars)), size = smp_size)
training <- mtcars[train_ind, ]

# Perform training
ensemble = randomForest::randomForest(mpg ~ ., data=training, ntree=1000,
importance=TRUE, proximity=TRUE)

D = createDisMatrix(ensemble, data=training, label = "mpg",
                         parallel = list(active=FALSE, no_cores = 1))

setting=list(impTotal=0.1, maxDec=(1*10^-6), n=2, level=5)
tree <- e2tree(mpg ~ ., training, D, ensemble, setting)

vi <- vimp(tree, training)
vi$vimp
vi$g_imp

}

}
