0

Hi there I am currently in the process of running at SVM data analysis and have got stuck with my SVM model:

library(caTools)
set.seed(123)
split<-sample.split(ult, SplitRatio = 0.8)
training_set<-subset(ult, split == 1)
ult$dns<-factor(ult$dns, labels = make.names(levels(ult$dns)))
str(ult)

test_set<-subset(ult, split == 0)
trainX <-data.frame(training_set)
str(training_set)

svm.model.ult <- svm(dns ~ ., data = trainX, type = "C-classification", cost = 1,gamma = 0.125, cross =10)
svm.pred.ult <- predict(svm.model.ult, test_set[,-7])
table(pred = svm.pred.ult, true = test_set[,7]

My code has been running fine until the last two steps (svm.pred.ult and table) as it returns a table with true and pred values but the pred values are only 0 so the table does not look right and code further on does not work.

r2evans
  • 141,215
  • 6
  • 77
  • 149
  • Welcome to SO, CallumPet! It would be easier for people to help you if your question is a more reproducible/self-contained. Please read https://stackoverflow.com/q/5963269, [mcve], and https://stackoverflow.com/tags/r/info for discussions on how to include sample data with your code. Also, a "nit" request: *minimal* working examples are highly encouraged, and your lines of `str(.)` are unnecessary; reducing the code the the smallest needed is very useful. (See https://stackoverflow.com/editing-help for formatting questions.) – r2evans Oct 04 '21 at 14:16
  • please provide all libraries loaded (you missed `library(e107)` from which you take the `svm` function). You missed a ")" in the last line of your code, but for the rest, your code works fine (tried with the `iris` dataset). As suggested by @r2evans you should provide a reproducible example or a sample of your data – Elia Oct 04 '21 at 14:49
  • true X0 X1 predictions X0 970 251 X1 0 0 – Callum Pet Oct 05 '21 at 11:25
  • an example of my output for the predict table is provided (I am unable to provide the data due to an NDA I signed). Is the reason there predictions are only X0 due to the model predicting the test_set will only produce X0's ? – Callum Pet Oct 05 '21 at 11:29

0 Answers0