forked from sandeepv59/Float_Internship
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSVM_sample.R
More file actions
29 lines (19 loc) · 858 Bytes
/
SVM_sample.R
File metadata and controls
29 lines (19 loc) · 858 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# library e1071 has functions for latent class analysis, short time Fourier transform, fuzzy clustering,
# support vector machines, shortest path computation, bagged clustering, naive Bayes classifier etc...
library(e1071)
data(iris)
head(iris)
plot(iris$Petal.Length, iris$Petal.Width, col = iris$Species)
col <- c("Petal.Length", "Petal.Width","Species")
# gives 100 samples between 1 to 150
s <- sample(150,100)
iris_train <- iris[s,col]
iris_test <- iris[-s,col]
svmfit <- svm(Species~.,data = iris_train, kernel = "linear", cost = 100, scale = FALSE)
plot(svmfit,iris_train[,col])
tuned <- tune(svm, Species~., data = iris_train, kernel = "linear", ranges = list(cost= c(0.01,0.1,1,10,100)))
summary(tuned)
p <- predict(svmfit, iris_test[,col],type = "class")
plot(p)
table(p,iris_test[,3])
mean(p==iris_test[,3])