0

I am using the svm function in the e1071 package of R. Using svm function I could get an accuracy of 74% for my data, but when I try to use the predict function for a test dataset, it returns all of the data in one of the two categories and shows 0 in the other. This is what the code looks like

test <- read.table(file.choose(), header=T)
pred <- predict(modelb, test)
summary(pred)
0   1 
101   0 
snehita varma
  • 21
  • 1
  • 3
  • 5
    Please update your question incorporating the tips provided in this question: http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example. – Chase Nov 28 '11 at 04:00

1 Answers1

1

One of the possibilities is that your training dataset is imbalanced.

Let's say that you have 100 of samples in class 0 and 1 sample in class 1. In some cases, the best solution is given by putting every new example in class 0.

A few solutions include :

  1. working on balanced datasets
  2. assigning different weights to the classes. I use the kernlab package but the code is not that different I think and there should be an option class.weight when you calculate your model.
gnat
  • 6,213
  • 108
  • 53
  • 73
Matahi
  • 31
  • 2