lin.6d<-read.csv("D:/Documents/Linear-6d.csv", header=TRUE) View(lin.6d) 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) print(svm.lin.6d) 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?