Is there any way to calculate variable importance in R for SVM regression and averaged neural networks?

I've been using caret package, that has varImp function in it

> m <- best.tune(svm, train.x = descr[rownames(tr[[i]]),2:ncol(descr)], 
train.y = tr[[i]][,1],  data = df, cost = 2^(seq(0,10,5))), 
tunecontrol = tune.control(sampling = "cross"))
> varImp(m)
 Error in UseMethod("varImp") : 
 no applicable method for 'varImp' applied to an object of class "svm"

According to the developer, this approach wasn't realized for SVM method

However, rminer package suggests such function as Importance. Though, it throws an error:

VariableImportance = Importance(svmFit, data=descr[rownames(tr[[i]]), 2:ncol(descr)],    
Error in Importance(svmFit, data = descr[rownames(tr[[i]]), 2:ncol(descr)],  : 
duplicate 'switch' defaults: 'lm == func...' and 'NULL'

You might take a look at this blog post on variable importance for neural network which also gives you ideas for graphical representation of NN with VI. Also see this Cross Validated question on VI for SVM and answers therein. You could calculate your VI for each of your set of models and take a look at the set of VIs across the board.

| cite | improve this answer | |

Unfortunately, there is no direct way to get such information with SVMs/NNs.

If you want, you can estimate the contribution of a single variable ad hoc by training a model on all variables except that specific variable. The difference in performance between that model and the one with all variables may then be considered the marginal contribution of that variable.

If time permits, you can perform this procedure for all variables.

| cite | improve this answer | |
  • $\begingroup$ So basically I can calculate variable importance as difference between models with and without desired variable, right? $\endgroup$ – Boddha Aug 1 '13 at 13:49
  • $\begingroup$ Yes. That's what I mean. $\endgroup$ – Marc Claesen Aug 1 '13 at 13:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.