2

I have been running into this error every time I try to implement ksvm. My code:

Train11<- read.csv('Train.csv', head=TRUE) 
Train11 <- (sapply(Train11, as.numeric)) #convert all data to numeric
Train11 <- as.data.frame(Train11)
ModelV2<-ksvm(CityAssessment~., data=Train11, type= "C-svc", kernel="vanilladot", C=0.1,prob.model=TRUE)  
 Setting default kernel parameters  
Error in indexes[[j]] : subscript out of bounds

I am not sure where I am going wrong. the dimensions of the dataset are 686 x 72. there aren't any NA values in the dataset (I've checked it!) and no infinite values either.

Many thanks!

lmo
  • 37,904
  • 9
  • 56
  • 69

2 Answers2

1

I had the same problem, turned out I had only one class in my target vector.

user2173836
  • 1,461
  • 2
  • 15
  • 19
1

For anyone reading this in the future. I had the same problem.

This is likely due to the way the kernlab package handles class probabilities (prob.model = TRUE) internally. If n is small or the classes are severely imbalanced, the internal 3-fold cv fails, probably for the reason user2173836 described.

Solutions:

1.) Set ksvm(..., prob.model = FALSE)

or

2.) Only run models with a large enough n and class balance. For my problem, running many single SVMs as baseline comparison to MTL-SVM, I could just skip over these "bad" tasks.

Dharman
  • 30,962
  • 25
  • 85
  • 135
hoopyfrood
  • 23
  • 3