# How much each variable contribute to my overall classification

Les say I have a data set with several measures and one factor (classification) like the one bellow (for the sake of simplicity, I'm simulating 10 rows and 5 variables only)

I'd like to know how much each variable contribute to the overall classification. I thought about running a linear regression, but I'm wondering if it makes sense to use it to "explain" a factor

When I run lm(classification ~ ., data =data) I get a warning saying

Warning messages:
1: In model.response(mf, "numeric") :
using type = "numeric" with a factor response will be ignored
2: In Ops.factor(y, z\$residuals) : ‘-’ not meaningful for factors


but I do get a result (intercept and coefficients for each variable).

My questions are: do they make any sense? And: is there a better way to get to the answer I'm looking for?

   classification  variable_1  variable_2 variable_3 variable_4 variable_5
1               5 -0.90174176 -0.64796703  1.2106427 -0.9229394 -0.6578518
2               5  1.75760214  0.18486432  0.2018499  0.1301168 -0.6510428
3               8 -0.29445029 -0.23108298 -2.6244614  0.3745607  0.3124868
4               4  0.78639724  1.04943276 -0.6047869 -0.4275781  0.6395614
5               3 -2.06554518  0.07336021  2.8142735  1.0558045 -0.1818247
6               4  0.04374419 -0.13775079  0.6132946 -0.5890983  1.9965892
7              10 -1.46731867  1.00367532 -0.8626940 -1.8378582  0.2702731
8               8  0.27206146 -0.13775707  2.6827356  1.5554446  0.1549394
9               5  0.58075881  2.03567118  0.2056770 -0.2935464 -1.3586576
10              9  0.57725709 -0.25396790  0.6640166 -1.9626897  0.3650243


Code to reproduce it:

data <- data.frame(classification=sample(3:10,replace=TRUE,size=10))

for(i in 1:5){
data[,paste0("variable_",i)]<-rnorm(10)
}


thanks

• Are you running a classification model at all, or is this linear regression the only modeling you've done? – Dougal Jul 13 '15 at 16:48
• thats the only one I've done so far, wondering if it is a good option – Diego Jul 13 '15 at 22:16