Skip to content

A repository for exploring SVM in R and Python. Part of notes repository series where I explore different concepts and technologies.

Notifications You must be signed in to change notification settings

AkaCoder404/svm-notes

Repository files navigation

SVM

This repository contains some work with SVM.

Resources

Some cool resources I have found about the topic

SVM with R

Iris One Dimensional

Graph of setosa (red) and virgina (blue)

alt text

Iris Two Dimensional

Linear Polynomial
RDF Sigmoid

Iris Three Dimens

alt text

XoR

alt text

Inner Outer

2D 3D
alt text

Heteroscedascity

Before SVM Radial
alt text alt text

Downstream Tasks

Face Recognition

When the testing dataset size is (656, 2914) and training dataset is (164, 2914) with 4 different classes (4 different faces), a make_pipeline with RandomizedPCA(n_components=150) and SVC(kernel='rbf', class_weight="balanced"), we have a training time and accuracy of.

Training time: 4.62 Accuracy: 89.02%

Unique Counts Confusion Matrix
alt text alt text

Compared to a simple MLPClassifier with a hiddenlayer of 1024.

Training time: 6.31894588470459 Accuracy: 92.07

Now, what if we increase the dataset size?

Text Classification

The original analysis can be found in ./Downstream/textclassification.ipynb. Now, this dataset is much bigger compared to the facial recognition with a training set of (41157, 5000) for training and (3798, 500) and for testing.

This is in a sense a sentiment analysis problem, where tweets are given a sentiment of one of 5 classes whose distribution is shown below.

alt text

alt text

Inference time is also extremely slow.

alt text

The training time is extremely long.

Let's compare this to a simple linear regression classifier.

Here is the heatmap side by side.

SVM Linear Linear Regression
alt text alt text

In terms of accuracy, SVM does perform better. However, it is not worth the training cost.

Now let's compare these results to a simple LSTM recurrent neural network. It should be noted that training was also done on CPU.

Stock Market analysis

In this example, we see that SVM can be used for regression tasks as well.

Here we select a couple of features. alt text

This produces a mean squared error of

Here we add one other feature, Previous Close. alt text

About

A repository for exploring SVM in R and Python. Part of notes repository series where I explore different concepts and technologies.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published