1

I am trying to make a prediction on unknown classed tuple using SVM in R. My CSV File containing training data is:

age,income,student,credit_rating,buys_computer
youth,high,no,fair,no
youth,high,no,excellent,no
middle_aged,high,no,fair,yes
senior,medium,no,fair,yes
senior,low,yes,fair,yes
senior,low,yes,excellent,no
middle_aged,low,yes,excellent,yes
youth,medium,no,fair,no
youth,low,yes,fair,yes
senior,medium,yes,fair,yes
youth,medium,yes,excellent,yes
middle_aged,medium,no,excellent,yes
middle_aged,high,yes,fair,yes
senior,medium,no,excellent,no

and the test CSV containing only a single tuple is:

age,income,student,credit_rating
youth,medium,yes,fair

My R code is:


library(RWeka)
library(e1071)

data <- read.csv('./Datasets/training-data-14-tuples.csv')
test <- read.csv('./Datasets/unknown-classed-tuple.csv')
classification <- svm(buys_computer~., data = data, kernel="linear")
prediction <- predict(classification, test) # <--- Error in this line
prediction

But it is showing an error:

Error in `contrasts<-`(`*tmp*`, value = contr.funs[1 + isOF[nn]]) : 
  contrasts can be applied only to factors with 2 or more levels

I have searched to fix the problem but everywhere I found that they are using test data which is a part of the training data (which itself contains the class value), but the class of my test data (provided by my teacher) is unknown.

This is one of my Lab Assignment but I cannot get the problem fixed.

NelsonGon
  • 13,015
  • 7
  • 27
  • 57
Chitholian
  • 432
  • 1
  • 10
  • 19

0 Answers0