# NOT RUN {
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
}
# }
Run the code above in your browser using DataLab