# Programming a Driverless Car Chapter 4 : Introduction to Supervised & Unsupervised learning

In supervised learning, we know what we are trying to predict. We use some examples that we (and the mode) know the answer to, to “train” our model. It can then generate predictions to examples we don’t know the answer to.

Examples: Predict the price a house will sell at. Identify the gender of someone based on a photograph. The overall aim of supervised learning is to train a model that can make predictions based on provided data, in the presence of uncertainty

Types of Supervised learning

Supervised learning can be further broken down based on two possible types of problem they may be trying to solve.

Classification problems: These are problems where there is a finite and countable number of possible solutions. These are categories or classes. There  may be as few as 2 or as many as 1000+ possible solutions, as long as we can identify and count them all this doesn’t matter.

• Examples: Identify plant species.

Regression Problems: These are problems where the feature we are trying to predict is a number on a continuous scale.

• Examples: Predict someone’s height.

## Supervised Learning Models

Some of the supervised learning Models are

• Nearest Neighbors (Used Classification and Regression)
• Decision Trees (Classification and Regression)
• Linear Regression (Regression)

Nearest Neighbours

This is conceptually one of the simplest technique, which uses the proximity or similarity of observations to make predictions about them. If a particular data is near to any data it recognizes the similarity between it.

Method

• For the 1-nearest neighbour algorithm, find the closest labelled observation to the unlabelled observation and apply the same label.
• While it may seem very simple, it is often very effective!
• It can be used for classification or regression

Nearest Neighbour Predictions

In this example, we have two different types of data sets. Circles and Crosses, let’s say from the set of object datas. We have to predict which type of object, round of cross one. The alg, finds the datatype (Shape) of the object nearby is and the nearest neighbor algorithm identifies it as X. Similarly, In this example, you wish to identify the object over here. In this case, the nearest object is the circle. The nearest neighbor algorithm will predict that it is a circle, which is nearby to the circle.

## Decision Trees (Supervised Learning)

Another Quite simple Machine Learning Technique

We attempt to “cut” the space where our observations exist and predict labels based on the sections our observations end up in.

• We can display these cuts in the form of a tree, hence the name.
• Here is an example of such a tree used for predicting height We cut this space with a line and try to predict a particular value , if the value lies into the space A or Space B (below). Once we have cut our space into chunks, how do we generate predictions in that area. Each cut should improve the prediction accuracy by as much as possible.

We can achieve this by having two types of Data where we have no assumptions about the data and then, we have no assumption of data. If we have no assumptions of data, it is not computationally efficient method. If we have lots of assumption, it is very computationally efficient. In nearest neighbour technique we have very less assumption of data. In linear regression,  there is a lot of assumption of data. Therefore, it is computationally a much more efficient technique. ## INTRODUCTION TO UNSUPERVISED LEARNING

Unsupervised Learning: We don’t know what we are trying to predict. We are trying to identify some naturally occurring patterns in the data which may be informative.  The work of an supervised algorithm would be to identify in how many data sets the value is decreasing to a very low value / magnitude.

Examples: Try to identify “Clusters” of customers based on data we have on them.

If you feed around 3000 images to the algorithm, the work of the algorithm would be to identify which of the images are common in concepts. In the case of an unsupervised learning, it categorizes without any annotation. In case of classification, the work of algorithm was to identify spam or not spam.

As a whole, we try to identify the clusters of data given to us. For example, the data sets of 10000 customers in a mall, we can identify the high value purchasers and low value purchasers, based on the products, value etc. This is done by identifying the common pattern of these consumers and segregate them.

## Clustering Analysis

For example, we have different images, which includes fruits and boxes. For an unsupervised algorithm, we cannot predict what type of clusters it will create. One of the clusters we may get is a cluster based on the shape.

In the second cluster it is also segregated based on the shape. The algorithm has categorized the images based on the common features, in this case, it’s shape.

Similar to that the three clusters could be classified based on their color as well. Here we have three cluster, which are completely unsupervised based on common features.

## Why Should we use Unsupervised Learning Techniques?

Collecting and labeling a large set of sample patterns (supervised) can be surprisingly costly. This is why Unsupervised comes into picture.

Eg. Videos are virtually free, but accurately labeling the video pixels is expensive and time consuming.

• To detect the gradual change of pattern over time.
• To find features that will then be used for categorizations.
• To gain insight into the nature or structure of the data during the early stages of an investigation.
• Identifying the gradual change of a pattern.
• To find features that will then be useful for categorization.
• To gain insight into the nature or structure of the data during the early stages of an investigation.
• Anomaly detection for Credit card pattern

An Example of unsupervised learning technique is working on astronomical data. We have a large data set of astronomical data, analysing each data set is going to be time consuming and expensive. Employing an unsupervised learning algorithm would be efficient in finding common pattern in the data sets.

Another example of Unsupervised algorithm would be analysing Social Media data sets, where

We try to find your networks and connections based on direct and indirect members of your circle and it suggests them based on different criterias.

## CLUSTERING

Clustering is the classification of objects into different groups, or more precisely, the partitioning of a data set into subsets (clusters), so that the data in each subset (ideally) share some common trait – often according to some defined distance measure.

One of the famous clustering techniques used is K Means Clustering.

In  K Means Clustering:

• We choose k initial centroids (Center Points)
• Each Cluster is associated with a centroid. We’ll create each cluster with each centroid.
• Each data object is assigned to closest centroid. The data which is closest to the centroid is assigned to that particular cluster
• The Centroid of each cluster is then updated based on the data objects assignment to the cluster.
• Repeat the assignment and update steps until convergence.

K MEANS Clustering Example Let us see here we wish to create, three clusters . We take three initial centroids,

K equals to K1 K2 K3 are three centroids, then the second step would be assigning the data set. that would be nearest to them, with the cluster nearest to the centroid.

All the elements next to centroid K1 has come into the cluster k1, All the elements next to centroid K2 has come into the cluster k2 and all the elements that are next to centroid k3 has come into the cluster k3.

Based on the data set in a particular centroid, we have to move the location of that respective centroid up to the mean location.

Finding the Mean of the cluster. Find the original elements to the mean of each clusters. We’ll be moving the K1 from it’s location to the mean of it. K2 from it’s location to the mean of it and so on. Once moved , this process will keep repeating till convergence. Next task is again checking the centroid which are the nearest element and again assigning as the item or element of that cluster. For example, this element was near k1, and now it’s near k2. So this will move to k2 cluster. Then k3 and so on. This is will keep on happening till divergence. To summarize, unsupervised data isn’t labelled data, here we do not know the value of the element in the data. We try to create clusters and categorize the elements of the data set in this method.

Recommended Reading: Introduction to Artificial Intelligence

Next: Chapter 5 LINEAR REGRESSION