Description Usage Arguments Details Value Author(s) See Also Examples
varimpPred calculates Variable Importance and makes predictions, it returns a list containing a data frame of variable importance scores, predictions or class probabilities, and corresponding plots.
1 2 3 4 5 6 7 8 9 10 |
newdata |
object of class "data.frame" having test data. |
y |
character. Target variable. |
positive |
character. The positive class for the target variable if y is factor. Usually, it is the first level of the factor. |
model |
expression. The model object returned after training a model on training data. |
scale |
boolean. If |
auc |
boolean. If |
predict |
boolean. If |
... |
additional arguments to be passed to |
The importance measure for each variable is calculated based on the type of model.
For example for linear models, the absolute value of the t-statistic of each parameter is used in the importance calculation.
For classification models, with the exception of classification trees, bagged trees and boosted trees, a variable importance score is calculated for each class. See varImp
for details on model-specific metrics.
varimpPred
can be used to obtain either variable importance metrics, predictions, class probabilities, or a combination of these.
For classification models with predict = TRUE
, class probabilities and ROC curve are given in the results.
For regression models with predict = TRUE
, predictions and residuals versus predicted plot are given.
A list object with importance measures for variables in newdata
, predictions for regression models, class probabilities for classification models, and corresponding plots.
newdata
should be either the test data that remains after splitting whole data into training and test sets, or a new data set different from the one used to train the model.
If y
is factor, class probabilities are calculated for each class. If y
is numeric, predicted values are calculated.
A ROC curve is created if predict = TRUE
and y
is factor. Otherwise, a plot of residuals versus predicted values is created if y
is numeric.
varimpPred
relies on packages caret
, ggplot2
and plotROC
to perform the calculations and plotting.
Zakaria Kehel, Bancy Ngatia, Khadija Aziz, Zainab Azough
varImp
,
predict.train
,
ggplot
,
geom_roc
,
calc_auc
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | if(interactive()){
# Calculate variable importance for classification model
data("septoriaDurumWC")
knn.mod <- tuneTrain(data = septoriaDurumWC,y = 'ST_S',method = 'knn')
testdata <- knn.mod$`Test Data`
knn.varimp<- varimpPred(newdata = testdata, y='ST_S', positive = 'R', model = knn.mod$Model)
knn.varimp
# Calculate variable importance and obtain class probabilities
data("septoriaDurumWC")
svm.mod <- tuneTrain(data = septoriaDurumWC, y = 'ST_S',method = 'svmLinear2',
predict = TRUE, positive = 'R',summary = twoClassSummary)
testdata <- svm.mod$`Test Data`
svm.varimp <- varimpPred(newdata = testdata, y = 'ST_S',
positive = 'R', model = svm.mod$Model,
ROC = TRUE, predict = TRUE)
svm.varimp
# Obtain variable importance plot for only first 20 variables
# with highest measure
svm.varimp <- varimpPred(newdata = testdata, y = 'ST_S',
positive = 'R', model = svm.mod$Model,
ROC = TRUE, predict = TRUE, top = 20)
svm.varimp
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.