1

Here is an example of the variables that I am working with

str(t.data)
'data.frame':   100 obs. of  99 variables:
$ MEMB_ID              : Factor w/ 100 levels ...
$ ORDER_DT             : Factor w/ 90 levels ...
$ SHIP_DT              : Factor w/ 80 levels ...
$ COMPANY_NM           : Factor w/ 98 levels ...
$ COMPANY_ADD          : Factor w/ 90 levels ...
$ SHIP_VENDOR_CD       : Factor w/ 10 levels "USPS" "FEDEX" "UPS" "DHL" ...

Here is the ksvm that I am trying to run.

m1 <- ksvm(SHIP_VENDOR_CD~.,data=t.data, kernel="rbfdot",C=5)

However, I am running into this error

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

I would greatly apperciate some help in debugging this error. I am not able to do a na.omit as according to this answer, but are there any other ways to get around this error?

Thanks,

B.Choi

B. Choi
  • 33
  • 1
  • 1
  • 6
  • Why can't you use `na.omit()`? The error message you are getting says your data (or the subset of the data you fed into the SVM) has a factor variable that only has one level. The code in https://stackoverflow.com/questions/44200195/ just shows you how to determine which variable that is. – Merik Jul 23 '18 at 19:15
  • I cannot delete the contents of the data.frame as the result is into few rows. Additionally, when I run summary, table, str with t.data$colum the output says it has more than one level. Is there any other way to debug this error? – B. Choi Jul 23 '18 at 19:26
  • What do you get if you convert each column in your data to a character and then back to a factor? Such as `t.data$COMPANY_NM <- as.factor(as.character(t.data$COMPANY_NM))` ? This will ensure your factors are recalculated and if a factor actually has only one label it will become apparent to you. – Merik Jul 23 '18 at 19:29

0 Answers0