user8512515
user8512515

Reputation: 21

KSVM (in r) giving - Error in indexes[[j]] : subscript out of bounds

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!

Upvotes: 2

Views: 852

Answers (3)

Ivalbert Pereira
Ivalbert Pereira

Reputation: 304

Once your model is a classification model ("C-svc"), check if response variable has two or more classes.

Upvotes: 0

hoopyfrood
hoopyfrood

Reputation: 23

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.

Upvotes: 1

user2173836
user2173836

Reputation: 1571

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

Upvotes: 1

Related Questions