0% found this document useful (0 votes)
4 views

Lecture 2 Machine Learning

مخخخفصسذرىةجتلييعناييلمكنلينمميصنموات

Uploaded by

Youssef Mohamed
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Lecture 2 Machine Learning

مخخخفصسذرىةجتلييعناييلمكنلينمميصنموات

Uploaded by

Youssef Mohamed
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 20

Dr.

Belal Badawy Lecture 2


1
Linear Regression Algorithm
 Establishes a relationship between the Independent & Dependent
Variables.
 It attempts to model relationship between two variables by fitting a line
called Linear Regression Line.
 The Linear Regression line is created using Ordinary Least Square
Method. Simple Linear Regression
X Y
Multiple Linear Regression
X1
Multiple X2
Predictors Y
X3
X4
2
Linear Regression Algorithm

Where: w,b are called parameters or coefficients


or weights

Linear regression with one variable


OR univariate linear regression 3
Linear Regression Algorithm

Slope/Gradient

y = mx + c Y Intercept
Residual Sum of Squared Error
What is Error?

• Actual Value – Predicted Value = Error

• Here Predicted Value is the value predicted by the Linear


Regression Model.

• Also known as Residual.


Why it is Important?
Cost function=
Smaller the residuals, more accurate model it would be.
Cost Function

Cost function : represent how to fit the possible straight line to


our data
Cost function=

Hypothesis (Function):
Parameters: w,b
Cost function:
Goal: minimize f(w,b)
Regression Line | Best Fit Line
What is the Line of Best Fit?
• The Best Fit Line is the line that gives the minimum SSE.
• Amongst all the possible lines, there will be one line that will
be the best fit meaning greatest possible accuracy as a model.
• The line that minimizes the sum of squared error of residuals
is called Regression Line or the Best Fit Line.
• In Simple Terms, it represents a straight line that best
represents the data on scatterplot. It is drawn using the Least
Square Method.
Use the Least Square Method to Determine the Eqn. of Line of
Best Fit
x 8 2 11 6 5 4 12 9 6 1

y 3 10 3 6 8 12 1 4 9 14
Finding Best Fit Line Algorithm
How to find the Best Fit Line?
• The equation of the straight line is given by y = mx +c
m – slope of the line
c - Intercept (The point at which the straight line touches y axis.
• The Best Fit line is found basis the Least Squared Method.

Algorithm:
Mean of x and y values
Step1: Find the Mean of x-values and y-values
Step2: Calculate the slope of the line. It can be found using the following eqn. on
the right.

Step3: Compute the y-intercept of the line using the formula


Finding m (Slope)
Finding Best Fit Line Algorithm
Use the Least Square Method to Determine the Eqn. of Line of Best Fit
Steps: Following Steps are deployed to achieve the objective.
Step1: Calculate the Mean of X and Ys

Step2: Find the Following:-


Finding Best Fit Line Algorithm
Step1: Calculate the Mean of X and Ys

The mean value of x is 6.4 and y is 7

Step2: Find the m (slope)

m (slope) = -131/118.4 = -1.1 approx.

Step3: Calculate the y intercept

b (intercept) = 7 – (-1.1) * 6.4 = 14.0 approx.

Thus, the equation of the line is y = -1.1x + 14


Regression Equation and Line of Best Fit
Gradient Descent

• Iterative solutions not only in linear regression , it’s actually


used all over the place in machine learning
• Objective : minimize any function (cost function f)
Gradient Descent
Gradient Descent
Gradient Descent
Gradient Descent
Gradient Descent
Gradient Descent
Gradient Descent
Thank you
20

You might also like