0

I was running an svm call from the package e1071 on R using the code below.

model = svm(AgeBucket~., data=mydata, control=svm.control(cp=0.01))

However, I get the below error.

Error in `contrasts<-`(`*tmp*`, value = contr.funs[1 + isOF[nn]]) : 
  contrasts can be applied only to factors with 2 or more levels

I searched around a bit and have tried the following but still the error persists.

  1. Removed all NAs
  2. Converted all columns to factors
  3. Called gc() the garbage collector after every fold of my k-fold cross validation
IAMTubby
  • 1,627
  • 4
  • 28
  • 40
  • 1
    give us a summary of your data,or a structure of your dataset – ECII Feb 13 '15 at 07:31
  • 1
    You need to use tabular methods to see which factors in mydata have only one factor. I don't see any code that shows how you did a "k-fold cross validation". It certainly seems possible that a sampling procedure would create a subsample with a restricted domain. – IRTFM Feb 13 '15 at 07:39
  • @BondedDust, thanks for the reply. Columns which are of class factor having just one value throughtout all columns was the culprit. Removing these columns got it to work. – IAMTubby Feb 19 '15 at 07:29

0 Answers0