# Experiment 5: SVM
This is the report of Experiment 5: SVM.
# Linear SVM - basic
# Purpose
In this part, we will use a basic linear SVM to classify a group of data. The train set and test set are given as file training_1.txt and test_1.txt.
# Procedure
A basic linear SVM with regular term can be formulated as
It's Lagrange duality problem is
After calculated that, we can get the parameters and by
where is the support set.
Then, we can draw the decision boundary and use the test set to examine whether the SVM reliable.
# Results & Answers
The train set and decision boundary is as follows.
<img src="../../../images/machineLearning/MLExp/Exp5/C=100.jpg" style="zoom:67%;" />
Then, I draw the line with and on the same diagram. But there are no significant difference.
<img src="../../../images/machineLearning/MLExp/Exp5/2.jpg" style="zoom:67%;" />
The result of this classifier on test set is
success: 500 | |
err: 0 |
There's no misclassified. That's amazing!
# Linear SVM for Handwritten Digit Recognition
# Purpose
Now, we will train a linear SVM on a simplified MNIST dataset, which only have the figure of 0 and 1. We need to classify them, and test whether the SVM classifier is reliable or not.
# Procedure
The main procedure is like the first part, but we should import the data and extract the features first.
We use the local binary pattern algorithm (LBP) to extract the feature.
Another different thing is that we can't directly visualize the data, so we evaluate the SVM classifier with error rate. And, we can print the misclassified case.
# Result & Answers
# without regularization
Without regularization term, we can get the classification result as follows.
train suc: 12665
train err: 0
test suc: 2112
test err: 3
Only 3 figure are misclassified. One of them is
<img src="../../../images/machineLearning/MLExp/Exp5/err%20case1.jpg" style="zoom:50%;" />
Maybe its feature is not so clear.
# with different regularization term
The order of magnitude of alpha is about 1e-6
. So I chose the regularization parameter from 1e-5
to 1e-9
. The results are as follows.
error rate on train set | error rate on test set | |
---|---|---|
+inf | (0/12665) | (3/2115) |
1e-4 | (5524/12665) | (939/2115) |
1e-5 | (5524/12665) | (939/2115) |
3e-6 | (1526/12665) | (232/2115) |
2e-6 | (758/12665) | (118/2115) |
1e-6 | (171/12665) | (32/2115) |
1e-7 | (31/12665) | (6/2115) |
1e-8 | (39/12665) | (4/2115) |
1e-9 | (61/12665) | (7/2115) |
I don't know why the error rate change like this. (That's why I out of due...)
# Non-Linear SVM
# Purpose
In this part, we will construct a non-linear SVM for classifying. The dataset given is training_3.txt.
# Procedure
Unlike linear SVM, non-linear SVM using a kernel to construct a mapping from low dimensional space to high dimensional space. In this experiment, we use the Radial Basis Function (RBF) kernel. The kernel has the formula:
where is a hyperparameter.
Because we change the kernel, we also need to change the decision function . Now, decision function can be calculated as
where and is the support set.
# Results and Answers
First, let's see the dataset without any decision boundary.
<img src="../../../images/machineLearning/MLExp/Exp5/dataset.jpg" style="zoom:67%;" />
It's easy to see that there is not a perfect linear boundary dividing all the data points. So we need a non-linear boundary.
With different , the results are as follows.
#
<img src="../../../images/machineLearning/MLExp/Exp5/gamma=1.jpg" style="zoom:67%;" />
#
<img src="../../../images/machineLearning/MLExp/Exp5/gamma=10.jpg" style="zoom:67%;" />
#
<img src="../../../images/machineLearning/MLExp/Exp5/gamma=100.jpg" style="zoom:67%;" />
#
<img src="../../../images/machineLearning/MLExp/Exp5/gamma=1000.jpg" style="zoom:67%;" />
We can see that may be the best choice.