1

I am running an SVM in R. when I run this code loading this data set. I get this error: the data set is located here

https://www.dropbox.com/s/hyrk3o72kmmpsq5/ds.csv?dl=0

install.packages("e1071")
install.packages("RTextTools")
library(e1071)
library(RTextTools)

store_9<-read.csv("_1_9_after_join.csv")
attach(store_9)
x <- subset(store_9, select=-volume_sales)
y <- volume_sales
svm_model <- svm(volume_sales ~ ., data=store_9)
summary(svm_model)
svm_model1 <- svm(x,y)
summary(svm_model1)
pred <- predict(svm_model1,x)
system.time(pred <- predict(svm_model1,x))
table(pred,y)

error:
> svm_model <- svm(volume_sales ~ ., data=store_9)
Error in `contrasts<-`(`*tmp*`, value = contr.funs[1 + isOF[nn]]) : 
contrasts can be applied only to factors with 2 or more levels
Box Box Box Box
  • 5,094
  • 10
  • 49
  • 67
Krish Kk
  • 21
  • 6

1 Answers1

0

You have an independent variable in your data that's categorical, but has only a single category (in other words, in R-speak, it's a factor variable with only one level). Based on a quick scan of your data, it looks like depart and snowfall could both be a problem. You also have several numeric variables that seem to always have the same value and shouldn't be in the model (though they aren't the cause of the error).

eipi10
  • 91,525
  • 24
  • 209
  • 285