Skip to content

Latest commit

 

History

History
 
 

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 

README.md

SVM

Implemented Perceptron, Kernel Perceptron, LinearSVM & SVM

Implemented Tensorflow & PyTorch backend for LinearSVM & SVM

Visualization

Perceptron

Perceptron on Two Clusters

Perceptron on Two Clusters

LinearSVM

LinearSVM on Two Clusters

LinearSVM on Two Clusters

TFLinearSVM

TFLinearSVM on Two Clusters

TFLinearSVM on Two Clusters

TorchLinearSVM

TorchLinearSVM on Two Clusters

TorchLinearSVM on Two Clusters

Kernel Perceptron

GD

Kernel Perceptron on Spiral

SMO

Kernel Perceptron on Spiral

SVM

GD

SVM on Spiral

SMO

SVM on Spiral

Example

from Util.Util import DataUtil
from e_SVM.SVM import SVM

x, y = DataUtil.gen_spiral(20, 4, 2, 2, one_hot=False)
y[y == 0] = -1                          # Get spiral dataset, Notice that y should be 1 or -1

svm = SVM()                             # Build SVM with SMO algorithm
svm.fit(x, y, kernel="poly", p=12)      # Train SVM (kernel: poly, degree: 12)
svm.evaluate(x, y)                      # Print out accuracy
svm.visualize2d(x, y, padding=0.1, dense=400, emphasize=svm["alpha"] > 0)
                                        # Visualize result (2d) (emphasized support vector)

Result

SVM on Spiral