简体   繁体   中英

Predict.svm function in e1071 package of R

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 

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM