lin.6d<-read.csv("D:/Documents/Linear-6d.csv", header=TRUE)


plot(lin.6d,col = ifelse(lin.6d$Class == 1, "red","blue")) 

library(e1071) # Package for Support Vector Machines

svm.lin.6d <- svm(Class ~ ., data = lin.6d, type = "C-classification", kernel = "linear", cost = 10, scale = FALSE)

tuned <- tune(svm, Class ~., data = lin.6d, kernel = "linear", ranges = list(cost=c(0.001,0.01,.1,1,10,100))) # Will show the optimal cost parameter
summary(tuned) # Optimal cost parameter is 10

# Find parameters of hyperplane (wx+c=0)
w <- t(svm.lin.6d$coefs) %*% svm.lin.6d$SV # In essence this finds the hyper plane that separates our points
c <- -svm.lin.6d$rho

The above code takes the data from an excel file "lin.6d" which contains vector points "X1,X2,X3,X4,X5,X6" and "Class:-1,1". So each vector point has a class 1 or -1.

I have plotted the data and colour coded each point depending on it's class (Blue if the point if it's class is -1, red otherwise).

I then used the svm function to obtain the coefficients of the hyperplane where: w is the set of coefficients (W1,W2,...,W6) and c is the intercept.

hence I got an answer: w=(0.02433109, 0.02803587, -0.02332039, -0.000118514, -0.009224677, -0.02626795) c= 0.1712391

where wx+c=0 is the equation of the hyperplane separating the classes of the points.

My question is: How do I know if this is the correct answer? How do I create a visual plot to show this can be represented as a line separating the classes?


I over complicated the answer I was looking for. If you have the equation of the hyperplane, you can test it against each point in the dataset. If all points of class 1 are ALL (above or below) the intercept and the converse is true for all points of class -1. Then the hyperplane separates the two classes


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.