Support Vector Machine (SVN)

To define our kingdoms, let's draw a line between our sand castles! Don't worry we can draw a curved line if necessary!

Supportive Horses and Flying Dogs! The aim for the SVN is to classify between two groups of data sets and draw a line between them. This is possible to find a subset of data for each group and determine the 'border' and classify two groups of datasets. The subset of the data that is uses here are supportive data points and hence from my kingdom a subset of horses, and from your kingdom the subset of flying dogs (apologies for my drawings!).

Seyed Hossein Ghotbi Support Vector Machines

Fig 1. Simplified look at SVN that classifies and predicts between two sets of data points within the given dataset.

Gift and Curse of SVN [consider buffer zones!]. As you noticed by now, we are looking at the subset of data points to classify. What does it mean for us? Well, it means it takes less computation time but there is no magic here, because we are not considering all data points overlapping occurs. , so some degree of tolerance you need to think about, so that you tolerate overlapping points (aka classificaiton errors).

Cost Parameter. We can create the buffer zones by using cost parameter where the degree of tolerance is determined. And to increase the tolerance level you need to have a bigger cost parameter. To what degree to push the cost parameter for accurate prediction, we need to use cross validation, that we will cover in its own post in the near future.

Summary. To find the optimal separation between two datasets with the given dataset use SVN. If you have small datasets, want to classify more than between two groups, and when you need to have a very large tolerance for classification to happen (this means you have too many overlapping data points), do not use SVN.

Artificial Intelligence Machine Learning Support Vector Machine SVN Classification Prediction

Posted by Seyed Hossein Ghotbi (Published on April 10, 2022).
What is K in K-NN, and What is K-NN Anyway?

Let's predict the pinky rabbit among other pinky rabbits, or detect a strange blue one!

Who has neighbours?! K-NN stands for K-nearest neighbours, and therefore even if we don't know what K is at this point, we know that its process is based on the close by neighbours just by its name alone. So if we think for a minute, we realise, oh a dataset that consists of a set of group-by data points (clusters) could be an input dataset for the K-NN.

Seyed Hossein Ghotbi K-nearest neighbours

Fig 1. Simplified look at K-NN that classifies and predicts based on nearest neighbours

Let's go one step further, a cluster of data points have similar values (that's why they are clustered after all!), so if I know the values of all the neighbours of a data point in the cluster, then it makes sense that somehow I could also predict the value of the unknown point. This is where K-NN comes in: it classifies the data points by majority of neighbours, and tries to predict the value.

How many neighbours do we need? Aha!, that is the question here as well as the meaning of K!. K means how many number of nearest neighbours we need to look at to predict the value?. This process is actually called parameter tuning. Which we cover will in future posts.

What if the rabbit is blue among all pink rabbits? So if we can predict the value of a data point within a group of data, then we should also be able to detect anomalies as well, an this is part of the predictive models' (such as K-NN) usage. Just a quick note here is that, the data size does matter in this case, because if our data size is small, then you have less data points to work with and that causes anomalies.

Artificial Intelligence Machine Learning K-nearest neighbours K-NN Predictive Analysis Anomaly Detection

Posted by Seyed Hossein Ghotbi (Published on April 2, 2022).
Supervised Vs. Unsupervised Learning in 30 Seconds

You want a human be in the loop? That is the question!

Silicon learns! We need our machines to "learn" (philosophical question right here, we will get to it in the future posts) from a dataset (e.g., all cat images posted on Reddit to date, or all tweet replies to a news post), and create a set of rules for prediction on future datasets (e.g., want to know whoever posts a picture on cat subreddit, is actually a cat and not a dog!).

The creation of rules, and how this creation is done is the core difference between machine learning algorithms that uses different processes for learning. Today, we look at two important ones: supervised and unsupervised learning.

Unsupervised Learning. to put it simply, the learning cycle on the given data is not interrupted ed by humans. To look at this the other way: we don't know what needs to be learned within the data for prediction, but however we want the unsupervised algorithm to find it. For example, when you go to an online store as a customer, and want to buy an item, the algorithm in the back of the online store could predict what is the likelihood of you buying the item based on your past purchases and the time of the year. This prediction happened by unsupervised learning algorithms that learn from all the purchase history of customers, and could come with the prediction.

Supervised Learning. here we as humans interrupt the learning by giving the machines ideas what to predict. For example, in our datasets we label the pictures of cats as 'cat' and dogs as 'dog' and then let the machine learn what is cat and what is dog, so in future a new image comes in the machine could predict if it is a cat or a dog.

Artificial Intelligence Machine Learning Supervised Learning Unsupervised Learning Supervised Vs. Unsupervised Learning

Posted by Seyed Hossein Ghotbi (Published on March 27, 2022).
Setup Your Mac for Deep Learning using PyTorch (CPU)
Blog post outcome: In this post we cover, how to setup your Mac and do some small Tensor operations and visualizations, for your future deep learning experience, using PyTorch.
Step 1: We need Python 🐍 🐍 🐍 (3.7+)

PyTorch will be imported in your Python code, so we need to write our PyTorch code in Python. Therefore first we need to check if we got Python 3 in our system. Simply open the Terminal, and typing the following: python --version . Here we get the following: Python 3.9.1. If you don't have Python 3, there is an official beginner guide for its installation on your system.

Step 2: We install NumPy & Matplotlib


Pytorch uses tensors (will cover this later, don't worry!) that are multi-dimensional arrays, and when we want to visualise them we convert them into Numpy arrays and by using matplotlib library we can visualise them. So let's install them both in our system.

pip3 install numpy matplot lib
Note: We are using pip3, and our installation is global on the system.

Step 3: Installation of PyTorch
Pytorch is a deep learning framework that help us to develop deep learning models for our machine learning projects and products. For installation on your Mac, use the following command:

pip3 install torch torchvision torchaudio
Note: In case later you want to use PyTorch with C++ or Java (No CUDA could be used), head over to PyTorch's installation documentation page.

Step 4: Jupyter Notebook
For coding environment we use Jupyter notebook, assuming that you want to get into PyTorch right away and experiment with it without struggling too much on choosing the light/heavy IDE side of things.

brew install jupyter

Step 5: Putting all together! 😄
Lets first fire up the Jupter notebook, so lets call it in the terminal:

jupyter-notebook

Note:This should be opening the local link in the browser. If not take a look a the link and copy/paste it in your browser to open it up. The link looks like the following:
http://localhost:8888/?token=54e3c4bna153f34ghbf842kj60f43717bf7a4g634b5a5cb

New Notebook (local):Then create a new notebook in Jupyter, by clicking on new on the top right corner and create a new Python 3 notebook.

Import the installed components. We installed Pytorch, NumPy and Matplotlib, lets import them in the first cell. Type the following and then do shift + Enter , to run the first cell.

import torch
import numpy as np
import matplotlib.pyplot as plt

If the cell ran without any issue, then congratulations! you are ready to play with PyTorch and visualise it on your machine. Thanks for reading this far. To be continued...

Artificial Intelligence Machine Learning Deep Learning PyTorch Jupyter Notebook NumPy Matplotlib

Posted by Seyed Hossein Ghotbi (Published on March 26, 2022).

Seyed Hossein Ghotbi Blog