Lec 3
Lec 3
Supriyo Mandal,
Ph.D. (IIT Patna)
Postdoc (ZBW, University of Kiel,
Germany)
Regression analysis – a set of statistical processes for estimating the relationships between a dependent variable and
one or more independent variables.
v Dependent variables are often called the 'predictand', 'outcome' or 'response' variable;
v Independent variables are often called 'predictors', 'covariates', 'explanatory variables' or 'features'.
v Regression analysis is a way of mathematically sorting out which of those variables does indeed have an
impact. Used for modeling the future relationship between the variables.
Statistical process – a science of collecting, exploring, organizing, analyzing, interpreting data and exploring patterns
and trends to answer questions and make decisions (Broad area).
y=a+bx
;a=intercept
b=slope/gradient/steep size
y= Dependent variable
x=independent variable
Basics of Regression Models
v Regression models predict a value of the Y variable given known values of the X variables.
v Prediction within the range of values in the dataset used for model-fitting is known as interpolation.
v Then the parameters of that model need to be estimated using any chosen method (e.g., least
squares).
Example..........
5 40
7 120
12 180
y:marks
16 210
20 240
y=a+bx
;a=intercept
b=slope/gradient/steep size
y= Dependent variable
x=independent variable x: hour
v a = a − L×Da
v 4. We repeat this process until our loss function is a very small value or ideally 0 (which means 0 error or 100%
accuracy). The value of b and a that we are left with now will be the optimum values.
v Now going back to our analogy, b can be considered the current position of the person. D is equivalent to the
steepness of the slope and L can be the speed with which he moves. Now the new value of b that we calculate
using the above equation will be his next position, and L×D will be the size of the steps he will take.
v When the slope is more steep (D is more) he takes longer steps and when it is less steep (D is less), he takes smaller
steps.
v Finally he arrives at the bottom of the valley which corresponds to our loss = 0.
v Now with the optimum value of b and a our model is ready to make predictions !
Linear Regression with Gradient Decent....
Example..........
Hour Marks
5 40
7 120
12 180
y:Marks
16 210
20 240
x: hour
Simple linear regression: There is only one continuous independent variable x and the assumed relation
between the independent variable and
the dependent variable y is
y = a + bx.
Details study.................
v Let x be the independent predictor variable and y the dependent variable.
v Assume that we have a set of observed values of x and y. A simple linear regression model defines the relationship between x
and y using a line defined by an equation in the following form:
y = a + bx
v To determine the optimal estimates of α and β, an estimation method known as Ordinary Least Squares (OLS).
v By solving eq(i)
�
=> 2 [�
�=1 �
− � − ���](-1) = 0
� � �
=> −2 �
�=1 �
+ 2� �=1
1 + 2� �
�=1 �
=0
� �
=> − �
�=1 �
+ �� + � �
�=1 �
=0
� �
=> �� = �
�=1 �
−� �
�=1 �
1 � 1 �
=> � = �
�=1 �
−� �
�=1 �
� �
=> � = � − ��
� � � �
where � = �
�=� �
(mean of values of y), � = �
�=� �
(mean of values of x)
� �
Details study.................
�
v E= �=1
(�� − ��)2
�
= �=1
[�� − (� + ���)]2
v To solve the above equation we have to take two partial derivations as below:
�� ��
v ��
=0 ------(i) and ��
=0 ------(ii)
v By solving eq(ii)
�
=> 2 �=1
[�� − � − ���](−��) = 0
� � �
=> −2 ��
�=1 � �
+ 2� �
�=1 �
+ 2� �2
�=1 �
=0
� � �
=> − ��
�=1 � �
+� �
�=1 �
+� �2
�=1 �
=0
� � �
=> − ��
�=1 � �
+ (� − ��) �
�=1 �
+� �2
�=1 �
=0
� � � �
=> �( �2
�=1 �
−� �)
�=1 �
= ��
�=1 � �
−� �
�=1 �
� � � �
=> �[ �{
�=1 � �=1
(�� − �)}] = �{
�=1 � �=1
(�� − �)}
�
�=� (��− �)
=> � = �
�=� (��− �)
1 n
By multiplying n−1
{ i=1
(xi − x)} in the numerator and denominator of RHS
1 � �
{ �=1 (��− �)} �=1 (��− �) ���(�,�)
=> � = �−1
1 � � =
�−1
{ �=1 (��− �)} �=1 (��− �)
���(�)
For problem and solutions........
https://www.ncl.ac.uk/webtemplate/ask-assets/external/maths-resources/statistics/regression-and-
correlation/simple-linear-regression.html
v We assume that there are N independent variables x1, x2, ⋯ , xN . Let the dependent variable be y.
v Let there also be n observed values of these variables:
v The multiple linear regression model defines the relationship between the N independent variables and the
dependent variable by an equation of the following form:
y = β0 + β1x1 + ⋯ + βNxN
v As in simple linear regression, here also we use the ordinary least squares (OLS) method to obtain the
optimal estimates of β0, β1, ⋯ , βN. The method yields the following procedure for the computation of these
optimal estimates. Let
B = (XT X)−1 XT Y
v Example:
v Fit a multiple linear regression model to the following data:
v Solution:
v In this problem, there are two independent variables and four sets of values of the variables. Thus, in the notations
used above, we have n = 2 and N = 4. The multiple linear regression model for this problem has the form
y = β0 + β1x 1 + β2x 2.
v The computations are shown below.
y = 2.0625 − 2.3750x1 + 3.2500x2