Supervised Learning
1. Regression Problem
In this problem we get Continous Variable (every time change) in output variable
a) Linear Regression
House Price Prediction
Area (Marla) No. of Rooms No. of Building Price (Output)
5 2 2 2500000
6 7 3 7400000
b) Logistic Regression
Blood Pressure ECG Sugar Heart Patient
(Output)
high normal no 0 (No)
medium high yes 1 (Yes)
low normal no 0 (No)
2. Classification Problem
Name Math Marks English Marks Grade
Haseeb 80 45 A
Arslan 55 65 B
Junaid 25 17 C
Linear Regression
Size in Feet (x) Price ($) (Y)
400 820$
600 1220$
800 1620$
900 1820$
Linear Regression Formula
Y = ax+b (a=2 ,b=20) Weights
Y = output
X = input
m = coefficient
C = slop
Logistic Regression (Binary (0,1)
Classification)
Classification Problem (Muticlass)
The multiclass classification is that problem where we have more than two classes in our label
class.
For example Dataset (Table) which have multiple disease column (Label)
Dataset (Table) with students Grade Column (A+, A, B+, B, C)
How Does a KNN Algorithm Work?
Consider a dataset that contains two variables: height (cm) & weight (kg). Each point is
classified as normal or underweight.
Man Body status Table (Dataset)
Based on the above data, you need to classify the following set as normal or underweight using
the KNN algorithm.
To find the nearest neighbors, we will calculate the Euclidean distance.The Euclidean distance
between two points in the plane with coordinates (x,y) and (a,b) is given by:
In KNN we dont nead to calculate weights it calculate the distance (Euclidean Distance) of our
given input to each row of our dataset and find the rows where our given input have less
distance
It will select that less distance rows and see output of that rows
It return the answer of our input with seeing highest row’s output
Suppose i gave input Weight = 57 and Height =170
Can you tell me at which point (Row) my input is most matched (Less Distance)
You will suggest me last 2 rows have least distance with our input ( Euclidean Distance)
Calculate (Euclidean Distance) from each row is in below table
Now, we have a new data point (x1, y1), and we need to determine its class.
KNN has have Neighbour variable (k) which is set by user for voting of atleast rows
If i set k=3
k=3 means it select 3 rows where we have least distance and then see the output of these three
rows which is “Normal” Class
So if i give it Weight = 57 and Height =170 then it will return me predicted class = Normal