Linear Algebra 1 - The ML context
The flow would be like Conept -> Visualization -> Maths -> Code
Introduction to a real life problem
• Notice how each fish is getting sorted into different buckets.
• Inherently, we know that there must be a scanner that analyses certain parameters.
Q. What do you think are the parameters based on which the sorting works?
• Weight
• Size
• Appearance
o Colour
o Shape and so on
To solve this automation task we would need the scanner to collect the data send it
somewhere (essentially a model), then the model make a prediction using the data and will
return the output to the seperator.
Terminologies
- So far what they did in previous modules was about analyzing the data given to them but
here the task is to predict a label using the data.
Let say that we are given a Labelled dataset ie a table as shown below
Q. What do you call these parameters that help us determine the fish type?
• It is called as features.
• They are also referred to as Independent variable
• We can record values of each features using a sensor.
Q. And this different type of fishes is known as?
• These are known as targets or is also called as labels or Dependent Variable.
• It tells us which type does a given row belong to
Now given a datapoint our job is to predict it's respective Label
Visualizing the data
So let's take the data that we have and plot them
• Since we have 3 features with us let's pick up 2 features which is height and width
and create a scatter plot to understand what is their replationship with each other as
well as their combined relationship with the target variable.
• This is a 2-D plot
• As we can see that we can have infinte number lines between green points and the
Blue points
Q. The question is which is the best line that we should pick that will help us speerate
Blue points from green points?
• This is the question that we will be solving in this entier module.
More ML Applications
IPL Win Prediction
T-Shirt size prediction
Basics of Lines
The basic equation of Line is
y = mx + c
This is also referred to as Slope intercept equation of a Line
• x is input and is an indepedent variable
• m is slope of the line ie the angle it makes with the x axis
• c is the y-intercept
• y is the output and is a dependant variable ie it is dependent on x given that we keep
m and c contant
For a given point (𝑥1x1,𝑦1y1) if it lies on our line 𝐿1L1 it should satisfy the equation of our
line and the equation would be
𝑦1=𝑚𝑥1+𝐶
The slope m can be calculated by calculating tan θ = 𝑦2−𝑦1/𝑥2−𝑥1
where (𝑥1,𝑦1) (𝑥2,𝑦2)are two coordinates on the line.
• Range of 𝑡𝑎𝑛 𝜃tan θ is from -∞∞ to ∞∞
• 𝑡𝑎𝑛(90) = ∞ due which there is a limitation which is using the slope intercept form
we cannot create a line which is 90 degrees to x-axis and to overcome this we use
general form of line
General form of Line
We might have already studied this form which is
Ax+By+c=0
• Now here instead of using A and B we are using W1 and W2
o In the ML context they are referred to as weights that the computer learns
• Instead of x and y we use x1 and x2 they both mean the same thing that it has 2
Dimensions
o In the ML context they are referred to as features which we saw above like
length, weight,etc.
• C is represented as W0
o In the ML context this is referred to as Bias
• We are essentially changing the way it is represented that is because we follow this
form of representation in Machine learning and the terminologies change when we
go to the Machine learning side of representation
We can convert general form of line into slope intercept form.
Now using the equation of m that we got after converting general form into slope intercept
form
• if we want to have a perpedicular line to x axis we know that m has to be infite and
we can do that by equating w2 to 0 and we can see that we have a line that is
perpedicular to x axis
Now if we want the y intercept to be equal to 1 using the new equation of the intecept
which is
−𝑤0𝑤2−w2w0 where if 𝑤2=0.8w2=0.8 then 𝑤0w0 should be equal to -0.8.
Parallel Lines
If 2 lines are parallel to each other then they will have same angle with the x-axis which
means that both the lines will have same slopes
Perpendicular lines
• The product of the slopes of 2 perpendicular lines is equal to -1
• if slope of line1 is 𝑚1m1 and slope of line2 is 𝑚2m2 then the formula to represent
slope of 2 perpendicular lines is
𝑚1∗𝑚2=−1m1∗m2=−1 which is equal to 𝑚1=−1𝑚2m1=−m21
• using the general form we have
o −𝑤1𝑤2∗−𝑤3𝑤4=−1
More than 2 dimensions
So this is called as the Generalized equation of a line
• 2D it is a Line
• 3D it is a plane
• 4D it is 4D hyperplane
• nD it is a nD hyperplane
The term hyperplanes because we cannot visualize beyound 3D
When we draw a line we can see that we are esentially diving the 2D space into 2 differnet
spaces
• one which lies above the line
• other is the one that lies below the line
Similarly in 3D we can divide the space into 2 parts using a Plane
• One which lines above the plane
• other is one that lies below the plane
And we can extend this concept till n dimensions
Why do we care about halfspaces?
• Whenever we are asked to classify a new datapoint we just plot the given datapoint
and see in which half space does it belong to using which we can classify the given
point.
• More on this we'll be clearing in the next class