-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSupervised Learning -c.Rmd
59 lines (46 loc) · 1.57 KB
/
Supervised Learning -c.Rmd
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
---
title: "Supervised Learning Part3"
author: "Yatish"
date: "October 15, 2015"
output: html_document
---
Reading Iris data
```{r}
require(ggplot2)
require(e1071)
require(kernlab)
iris<- read.table("iris.data",sep=",")
colnames(iris)<-c("SepalLength","SepalWidth","PetalLength","petalWidth","Species")
```
## Answer 1
Classifying the data using SVM
```{r}
svm.fit<- svm(Species~.,data=iris, kernal="linear",cost=10,scale=FALSE)
plot(svm.fit,iris,SepalLength~PetalLength)
```
Classifier was able to classify iris setosa with an ease but not the other two species. Model needs improvement.
## Answer 2
Trying different kernels:
```{r}
svmfit1<-svm(Species~.,data=iris,kernal="radial",gamma=1,cost=100000)
plot(svmfit1,iris,SepalLength~PetalLength)
svm.fit<- svm(Species~.,data=iris, kernal="sigmoid",gamma=1,scale=FALSE)
plot(svm.fit,iris,SepalLength~PetalLength)
```
trying different kernels wouldn't affect the performance much until we tune out the best model.
## Answer 3
To improve the performance we can use tune function to determine the best cost and gamma range and then choose bestmodel to classify.
```{r}
tune.out<- tune(svm,Species~.,data=iris,kernal="linear",ranges=list(cost=c(0.001,0.01,0.1,1,5,10,100)))
bestmodel=tune.out$best.model
summary(bestmodel)
```
```{r}
svm.fit<- svm(Species~.,data=iris, kernal="linear",cost=1,scale=FALSE)
plot(svm.fit,iris,SepalLength~PetalLength)
```
```{r}
svmfit1<-svm(Species~.,data=iris,kernal="radial",gamma=0.25,scale=FALSE)
plot(svmfit1,iris,SepalLength~PetalLength)
```
By tuning out the best model we can see the improvement in classification