Python-Linear Regression
Python-Linear Regression
Python-Linear Regression
www.intellipaat.com
A technique of finding the relationship between two or
more variables
Change in dependent variable is associated with a
Regression?
www.intellipaat.com
Regression is a technique that displays the relationship
between variable “y” based on the values of variable “x”.
Regression?
www.intellipaat.com
Temperature vs. Number of cones sold at ice cream store
Use Case
If you think there is a relationship between
two things regression would help confirm it!
www.intellipaat.com
There are various types of Regression, but we will focus on:
Linear Regression
Regression
www.intellipaat.com
LINEAR REGRESSION LOGISTIC REGRESSION
www.intellipaat.com
Simple linear regression is useful for finding
www.intellipaat.com
Y
Understandin Line
Dependent Variable
g Linear
Regression
X
Independent Variable
www.intellipaat.com
Y
Understandin +ve
Dependent Variable
g Linear
Regression
X
Independent Variable
www.intellipaat.com
Y
Understandin
Dependent Variable
g Linear
Regression
-ve
X
Independent Variable
www.intellipaat.com
Y
Line
Understandin
Dependent Variable
g Linear
Regression
X
Independent Variable
www.intellipaat.com
Y
Line of Linear
Regression
Understandin
Dependent Variable
g Linear
Regression
X
Independent Variable
www.intellipaat.com
Y
Understandin
Dependent Variable
g Linear
Regression Observation
X
Independent Variable
www.intellipaat.com
Y
Regression Line
Dependent Variable
g Linear
Regression
X
Independent Variable
www.intellipaat.com
Y
error
Dependent Variable
g Linear error
Regression
Actual Value
X
Independent Variable
www.intellipaat.com
Y
Understandin
Dependent Variable
g Linear
Regression
Minimize the
error
X
Independent Variable
www.intellipaat.com
Y
g Linear
Distance
Regression
X
Speed
www.intellipaat.com
Y
Understandin y = mx + c
g Linear
Distance
Distance travelled
in a fixed duration
Regression of time
X
Speed
www.intellipaat.com
Y
Speed of
Understandin
Vehicle
y = mx + c
g Linear
Distance
Regression
X
Speed
www.intellipaat.com
Y
Understandin y = mx + c
g Linear
Distance
m = +ve slope of line
Regression
X
Speed
www.intellipaat.com
Y
Understandin y = mx + c
g Linear
Distance
Regression
c = y - intercept of the line
X
Speed
www.intellipaat.com
Y
Understandin y = - mx + c
g Linear
Time
Time taken to travel
a fixed distance
X
Speed
www.intellipaat.com
Y
Independent Variable
Understandin
Dependent Variable
y = mx + c
Regression
X
Independent Variable
www.intellipaat.com
Understanding Linear
Regression
𝑥 𝑦
Y 1 4
D ependent
Variable 2 3
5 3 4
4 2
4 5 5
3
1
X
0 1 2 3 4 5 6 I ndependent Variable
www.intellipaat.com
Understanding Linear
Regression
𝑥 𝑦
Y 1 4
D ependent
Variable 2 3
5 3 4
4 2
4 5 5
3
1
X
0 1 2 3 4 5 6 I ndependent Variable
www.intellipaat.com
Understanding Linear
Regression
𝑥 𝑦
Y 1 4
D ependent
Variable 2 3
5 3 4
4 2
4 5 5
3
1
X
0 1 2 3 4 5 6 I ndependent Variable
www.intellipaat.com
Understanding Linear
Regression
𝑥 𝑦
Y 1 4
D ependent
Variable 2 3
5 3 4
4 2
4 5 5
3 mean: 𝒙 3 3.6
18/ mean : 𝒚
5
2
1
X
0 1 2 3 4 5 6 I ndependent Variable
www.intellipaat.com
Understanding Linear
Regression
𝑥 𝑦
y = mx+c 1 4
Y
D ependent
Variable 2 3
5 3 4
4 2
4 5 5
3 ( , ) mean 3 3.6
1
X
0 1 2 3 4 5 6 I ndependent Variable
www.intellipaat.com
Understanding Linear
Regression
𝑥 𝑦
y = mx+c 1 4
Y
D ependent
Variable 2 3
5 3 4
4 2
4 5 5
3 ( 3 , 3.6 ) mean
1
X
0 1 2 3 4 5 6 I ndependent Variable
www.intellipaat.com
Understanding Linear
Regression
𝑥 𝑦
y = mx+c 1 4
Y
D ependent
Variable 2 3
5 3 4
4 2
4 5 5
3 mean 3 3.6
2 𝛴 (𝑥 − 𝑥)(𝑦 − 𝑦)
m=
1 𝛴 𝑥−𝑥 2
X
0 1 2 3 4 5 6 I ndependent Variable
www.intellipaat.com
Understanding Linear
Regression
𝑥 𝑦 𝑥−𝑥
y = mx+c 1 4
Y
D ependent
Variable 2 3
5 3 4
4 2
4 5 5
3 mean 3 3.6
2 𝛴 (𝑥 − 𝑥)(𝑦 − 𝑦)
m=
1 𝛴 𝑥−𝑥 2
X
0 1 2 3 4 5 6 I ndependent Variable
www.intellipaat.com
Understanding Linear
Regression
𝑥 𝑦 𝑥−𝑥
Y
y = mx+c 1 4 1 −3
D ependent
Variable 2 3
5 3 4
4 2
4 5 5
3 mean 3 3.6
2 𝛴 (𝑥 − 𝑥)(𝑦 − 𝑦)
m=
1 𝛴 𝑥−𝑥 2
X
0 1 2 3 4 5 6 I ndependent Variable
www.intellipaat.com
Understanding Linear
Regression
𝑥 𝑦 𝑥−𝑥
Y
y = mx+c 1 4 −2
D ependent
Variable 2 3
5 3 4
4 2
4 5 5
3 mean 3 3.6
2 𝛴 (𝑥 − 𝑥)(𝑦 − 𝑦)
m=
1 𝛴 𝑥−𝑥 2
X
0 1 2 3 4 5 6 I ndependent Variable
www.intellipaat.com
Understanding Linear
Regression
𝑥 𝑦 𝑥−𝑥
Y
y = mx+c 1 4 −2
D ependent
Variable 2 3
5 3 4
4 2
4 5 5
3 mean 3 3.6
2 𝛴 (𝑥 − 𝑥)(𝑦 − 𝑦)
m=
1 𝛴 𝑥−𝑥 2
X
0 1 2 3 4 5 6 I ndependent Variable
www.intellipaat.com
Understanding Linear
Regression
𝑥 𝑦 𝑥−𝑥
Y
y = mx+c 1 4 −2
2 −3
D ependent
Variable 2 3
5 3 4
4 2
4 5 5
3 mean 3 3.6
2 𝛴 (𝑥 − 𝑥)(𝑦 − 𝑦)
m=
1 𝛴 𝑥−𝑥 2
X
0 1 2 3 4 5 6 I ndependent Variable
www.intellipaat.com
Understanding Linear
Regression
𝑥 𝑦 𝑥−𝑥
Y
y = mx+c 1 4 −2
−1
D ependent
Variable 2 3
5 3 4 0
4 2 1
4 5 5 2
3 mean 3 3.6
2 𝛴 (𝑥 − 𝑥)(𝑦 − 𝑦)
m=
1 𝛴 𝑥−𝑥 2
X
0 1 2 3 4 5 6 I ndependent Variable
www.intellipaat.com
Understanding Linear
Regression
𝑥 𝑦 𝑥−𝑥 𝑦−𝑦
Y
y = mx+c 1 4 −2
−1
D ependent
Variable 2 3
5 3 4 0
4 2 1
44 5 5 2
3 mean 3 3.6
2 𝛴 (𝑥 − 𝑥)(𝑦 − 𝑦)
m=
1 𝛴 𝑥−𝑥 2
X
0 1 2 3 4 5 6 I ndependent Variable
www.intellipaat.com
Understanding Linear
Regression
𝑥 𝑦 𝑥−𝑥 𝑦−𝑦
Y
y = mx+c 1 4 −2 4 −3.6
−1
D ependent
Variable 2 3
5 3 4 0
4 2 1
4 5 5 2
3 mean 3 3.6
2 𝛴 (𝑥 − 𝑥)(𝑦 − 𝑦)
m=
1 𝛴 𝑥−𝑥 2
X
0 1 2 3 4 5 6 I ndependent Variable
www.intellipaat.com
Understanding Linear
Regression
𝑥 𝑦 𝑥−𝑥 𝑦−
−𝑦
Y
y = mx+c 1 4 −2 0.4
−1
D ependent
Variable 2 3
5 3 4 0
4 2 1
4 5 5 2
3 mean 3 3.6
2 𝛴 (𝑥 − 𝑥)(𝑦 − 𝑦)
m=
1 𝛴 𝑥−𝑥 2
X
0 1 2 3 4 5 6 I ndependent Variable
www.intellipaat.com
Understanding Linear
Regression
𝑥 𝑦 𝑥−𝑥 𝑦−𝑦
Y
y = mx+c 1 4 −2 0.4
−1 3 − 3.6
D ependent
Variable 2 3
5 3 4 0
4 2 1
4 5 5 2
3 mean 3 3.6
2 𝛴 (𝑥 − 𝑥)(𝑦 − 𝑦)
m=
1 𝛴 𝑥−𝑥 2
X
0 1 2 3 4 5 6 I ndependent Variable
www.intellipaat.com
Understanding Linear
Regression
𝑥 𝑦 𝑥−𝑥 𝑦−𝑦
Y
y = mx+c 1 4 −2 0.4
D ependent
Variable 2 3 −1 − 0.6
5 3 4 0 0.4
4 2 1 − 1.6
4 5 5 2 1.4
3 mean 3 3.6
2 𝛴 (𝑥 − 𝑥)(𝑦 − 𝑦)
m=
1 𝛴 𝑥−𝑥 2
X
0 1 2 3 4 5 6 I ndependent Variable
www.intellipaat.com
Understanding Linear
Regression
𝑦 2
𝑥 𝑥−𝑥 𝑦−𝑦 𝑥−𝑥
Y
y = mx+c 1 4 −2 0.4 4
D ependent
Variable 2 3 −1 − 0.6 1
5 3 4 0 0.4 0
4 2 1 − 1.6 1
4 5 5 2 1.4 4
3 mean 3 3.6
2 𝛴 (𝑥 − 𝑥)(𝑦 − 𝑦)
m=
1 𝛴 𝑥−𝑥 2
X
0 1 2 3 4 5 6 I ndependent Variable
www.intellipaat.com
Understanding Linear
Regression
𝑥 𝑦 𝑥−𝑥 𝑦−𝑦 𝑥−𝑥 2 (𝑥 − 𝑥)(𝑦 − 𝑦 )
Y
y = mx+c 1 4 −2 0.4 4 -2 x 0.4
D ependent
Variable 2 3 −1 − 0.6 1
5 3 4 0 0.4 0
4 2 1 − 1.6 1
4 5 5 2 1.4 4
3 mean 3 3.6
2 𝛴 (𝑥 − 𝑥)(𝑦 − 𝑦)
m=
1 𝛴 𝑥−𝑥 2
X
0 1 2 3 4 5 6 I ndependent Variable
www.intellipaat.com
Understanding Linear
Regression
𝑥 𝑦 𝑥−𝑥 𝑦−𝑦 𝑥−𝑥 2 (𝑥 − 𝑥)(𝑦 − 𝑦 )
Y
y = mx+c 1 4 −2 0.4 4 -0.8
D ependent
Variable 2 3 −1 − 0.6 1 0.6
5 3 4 0 0.4 0 0
4 2 1 − 1.6 1 -1.6
4 5 5 2 1.4 4 2.8
3 mean 3 3.6
2 𝛴 (𝑥 − 𝑥)(𝑦 − 𝑦)
m=
1 𝛴 𝑥−𝑥 2
X
0 1 2 3 4 5 6 I ndependent Variable
www.intellipaat.com
Understanding Linear
Regression
𝑥 𝑦 𝑥−𝑥 𝑦−𝑦 𝑥−𝑥 2 (𝑥 − 𝑥)(𝑦 − 𝑦 )
Y
y = mx+c 1 4 −2 0.4 4 -0.8
D ependent
Variable 2 3 −1 − 0.6 1 0.6
5 3 4 0 0.4 0 0
4 2 1 − 1.6 1 -1.6
4 5 5 2 1.4 4 2.8
3 mean 3 3.6 𝛴 = 10 𝛴=1
2 𝛴 (𝑥 − 𝑥)(𝑦 − 𝑦)
m=
1 𝛴 𝑥−𝑥 2
X
0 1 2 3 4 5 6 I ndependent Variable
www.intellipaat.com
Understanding Linear
Regression
𝑥 𝑦 𝑥−𝑥 𝑦−𝑦 𝑥−𝑥 2 (𝑥 − 𝑥)(𝑦 − 𝑦 )
Y
y = mx+c 1 4 −2 0.4 4 -0.8
D ependent
Variable 2 3 −1 − 0.6 1 0.6
5 3 4 0 0.4 0 0
4 2 1 − 1.6 1 -1.6
4 5 5 2 1.4 4 2.8
3 mean 3 3.6 𝛴 = 10 𝛴=1
2 𝛴 (𝑥 − 𝑥)(𝑦 − 𝑦) 1
m= =
1 𝛴 𝑥−𝑥 2 10
X
0 1 2 3 4 5 6 I ndependent Variable
www.intellipaat.com
Understanding Linear
Regression
𝑥 𝑦 𝑥−𝑥 𝑦−𝑦 𝑥−𝑥 2 (𝑥 − 𝑥)(𝑦 − 𝑦 )
Y
y = mx+c 1 4 −2 0.4 4 -0.8
D ependent
Variable 2 3 −1 − 0.6 1 0.6
5 3 4 0 0.4 0 0
4 2 1 − 1.6 1 -1.6
4 5 5 2 1.4 4 2.8
3 mean 3 3.6 𝛴 = 10 𝛴=1
2 𝛴 (𝑥 − 𝑥)(𝑦 − 𝑦)
m= = 0.1
1 𝛴 𝑥−𝑥 2
X
0 1 2 3 4 5 6 I ndependent Variable
www.intellipaat.com
Understanding Linear
Regression
𝑥 𝑦 𝑥−𝑥 𝑦−𝑦 𝑥−𝑥 2 (𝑥 − 𝑥)(𝑦 − 𝑦 )
Y
y = mx+c 1 4 −2 0.4 4 -0.8
D ependent
Variable 2 3 −1 − 0.6 1 0.6
3.6
5 3 4 0 0.4 0 0
4 2 1 − 1.6 1 -1.6
4 5 5 2 1.4 4 2.8
3 mean 3 3.6 𝛴 = 10 𝛴=1
2 𝛴 (𝑥 − 𝑥)(𝑦 − 𝑦)
m= = 0.1
1 𝛴 𝑥−𝑥 2
X
0 1 2 3 4 5 6 I ndependent Variable
www.intellipaat.com
Understanding Linear
Regression
𝑥 𝑦 𝑥−𝑥 𝑦−𝑦 𝑥−𝑥 2 (𝑥 − 𝑥)(𝑦 − 𝑦 )
Y
y = mx+c 1 4 −2 0.4 4 -0.8
D ependent
Variable 2 3 −1 − 0.6 1 0.6
0.1
5 3 4 0 0.4 0 0
4 2 1 − 1.6 1 -1.6
4 5 5 2 1.4 4 2.8
3 mean 3 3.6 𝛴 = 10 𝛴=1
2 𝛴 (𝑥 − 𝑥)(𝑦 − 𝑦)
m= = 0.1
1 𝛴 𝑥−𝑥 2
X
0 1 2 3 4 5 6 I ndependent Variable
www.intellipaat.com
Understanding Linear
Regression
𝑥 𝑦 𝑥−𝑥 𝑦−𝑦 𝑥−𝑥 2 (𝑥 − 𝑥)(𝑦 − 𝑦 )
Y
y = mx+c 1 4 −2 0.4 4 -0.8
D ependent
Variable 2 3 −1 − 0.6 1 0.6
3
5 3 4 0 0.4 0 0
4 2 1 − 1.6 1 -1.6
4 5 5 2 1.4 4 2.8
3 mean 3 3.6 𝛴 = 10 𝛴=1
2 𝛴 (𝑥 − 𝑥)(𝑦 − 𝑦)
m= = 0.1
1 𝛴 𝑥−𝑥 2
X
0 1 2 3 4 5 6 I ndependent Variable
www.intellipaat.com
Understanding Linear
Regression
𝑥 𝑦 𝑥−𝑥 𝑦−𝑦 𝑥−𝑥 2 (𝑥 − 𝑥)(𝑦 − 𝑦 )
Y
y = mx+c 1 4 −2 0.4 4 -0.8
D ependent
Variable
3.6 = 0.3 + 𝑐 2 3 −1 − 0.6 1 0.6
5 3 4 0 0.4 0 0
4 2 1 − 1.6 1 -1.6
4 5 5 2 1.4 4 2.8
3 mean 3 3.6 𝛴 = 10 𝛴=1
2 𝛴 (𝑥 − 𝑥)(𝑦 − 𝑦)
m= = 0.1
1 𝛴 𝑥−𝑥 2
X
0 1 2 3 4 5 6 I ndependent Variable
www.intellipaat.com
Understanding Linear
Regression
𝑥 𝑦 𝑥−𝑥 𝑦−𝑦 𝑥−𝑥 2 (𝑥 − 𝑥)(𝑦 − 𝑦 )
Y
y = mx+c 1 4 −2 0.4 4 -0.8
D ependent
Variable 3.6 − 0.3 = 𝑐 2 3 −1 − 0.6 1 0.6
5 3 4 0 0.4 0 0
4 2 1 − 1.6 1 -1.6
4 5 5 2 1.4 4 2.8
3 mean 3 3.6 𝛴 = 10 𝛴=1
2 𝛴 (𝑥 − 𝑥)(𝑦 − 𝑦)
m= = 0.1
1 𝛴 𝑥−𝑥 2
X
0 1 2 3 4 5 6 I ndependent Variable
www.intellipaat.com
Understanding Linear
Regression
𝑥 𝑦 𝑥−𝑥 𝑦−𝑦 𝑥−𝑥 2 (𝑥 − 𝑥)(𝑦 − 𝑦 )
Y
y = mx+c 1 4 −2 0.4 4 -0.8
D ependent
Variable
3.3 = 𝑐 2 3 −1 − 0.6 1 0.6
5 3 4 0 0.4 0 0
4 2 1 − 1.6 1 -1.6
4 5 5 2 1.4 4 2.8
3 mean 3 3.6 𝛴 = 10 𝛴=1
2 𝛴 (𝑥 − 𝑥)(𝑦 − 𝑦)
m= = 0.1
1 𝛴 𝑥−𝑥 2
X
0 1 2 3 4 5 6 I ndependent Variable
www.intellipaat.com
Understanding Linear
Regression
𝑥 𝑦 𝑥−𝑥 𝑦−𝑦 𝑥−𝑥 2 (𝑥 − 𝑥)(𝑦 − 𝑦 )
Y
y = mx+c 1 4 −2 0.4 4 -0.8
D ependent
Variable
3.3 = 𝑐 2 3 −1 − 0.6 1 0.6
5 3 4 0 0.4 0 0
4 2 1 − 1.6 1 -1.6
4 5 5 2 1.4 4 2.8
3 mean 3 3.6 𝛴 = 10 𝛴=1
c=3.3
2 𝛴 (𝑥 − 𝑥)(𝑦 − 𝑦)
m= = 0.1
1 𝛴 𝑥−𝑥 2
X
0 1 2 3 4 5 6 I ndependent Variable
www.intellipaat.com
Understanding Linear
Regression
𝑥 𝑦 𝑥−𝑥 𝑦−𝑦 𝑥−𝑥 2 (𝑥 − 𝑥)(𝑦 − 𝑦 )
Y
y = mx+c 1 4 −2 0.4 4 -0.8
D ependent
Variable
3.3 = 𝑐 2 3 −1 − 0.6 1 0.6
5 3 4 0 0.4 0 0
4 2 1 − 1.6 1 -1.6
4 5 5 2 1.4 4 2.8
3 mean 3 3.6 𝛴 = 10 𝛴=1
c=3.3
2 𝛴 (𝑥 − 𝑥)(𝑦 − 𝑦)
m= = 0.1
1 𝛴 𝑥−𝑥 2
Equation of Regression line for m = 0.1, c = 3.3 is:
X
0 1 2 3 4 5 6 I ndependent Variable
y = 0.1x+3.3
www.intellipaat.com
Mean Square Error
m = 0.1
Y
D ependent c = 3.3
Variable
y = 0.1x + 3.3
5
For given m = 0.1 & c = 3.3 ,
4 Lets predict values for y when
x = {1,2,3,4,5}
3
y = 0.1 x 1+ 3.3 = 3.2
y = 0.1 x 2+ 3.3= 3.1
2 y = 0.1 x 3+ 3.3= 3.0
y = 0.1 x 4+ 3.3= 2.9
y = 0.1 x 5+ 3.3= 2.8
1
X I ndependent
Variable
0 1 2 3 4 5 6
www.intellipaat.com
Mean Square Error
m = 0.1
Y
D ependent c = 3.3
Variable
y = 0.1x + 3.3
5
For given m = 0.1 & c = 3.3 ,
4 L ine of Regression
Lets predict values for y when
x = {1,2,3,4,5}
3
y = 0.1 x 1+ 3.3 = 3.2
y = 0.1 x 2+ 3.3= 3.1
2 y = 0.1 x 3+ 3.3= 3.0
y = 0.1 x 4+ 3.3= 2.9
y = 0.1 x 5+ 3.3= 2.8
1
X I ndependent
Variable
0 1 2 3 4 5 6
www.intellipaat.com
Finding the best Fit Line
www.intellipaat.com
Goodness of Fit – 𝑹𝟐
𝑥 𝑦𝑝
Y 1 3.2
D ependent
Variable 2 3.1
5 3 3.0
4 2.9
4 L ine of Regression
5 2.8
3
𝑅2 =
𝛴 (Predicted Distance – Mean)2
1 𝛴 𝑦𝑝 − 𝑦
2
𝑅2 =
X I ndependent 𝛴 𝑦−𝑦 2
Variable
0 1 2 3 4 5 6
www.intellipaat.com
Goodness of Fit – 𝑹𝟐
𝑥 𝑦 𝑦𝑝 (𝑦𝑝 − 𝑦)
Y 1 4 3.2 3.2-3.6
D ependent
Variable 2 3 3.1
5 3 4 3.0
4 2 2.9
4 L ine of Regression
5 5 2.8
3
1 𝛴 𝑦𝑝 − 𝑦
2
𝑅2 =
X I ndependent 𝛴 𝑦−𝑦 2
Variable
0 1 2 3 4 5 6
www.intellipaat.com
Goodness of Fit – 𝑹𝟐
𝑥 𝑦 𝑦𝑝 (𝑦𝑝 − 𝑦) (𝑦 − 𝑦)
Y 1 4 3.2 -0.4 4 – 3.6
D ependent
Variable 2 3 3.1 -0.5
5 3 4 3.0 -0.6
4 2 2.9 -0.7
4 L ine of Regression
5 5 2.8 -0.8
3
1 𝛴 𝑦𝑝 − 𝑦
2
𝑅2 =
X I ndependent 𝛴 𝑦−𝑦 2
Variable
0 1 2 3 4 5 6
www.intellipaat.com
Goodness of Fit – 𝑹𝟐
𝑥 𝑦 𝑦𝑝 (𝑦𝑝 − 𝑦) (𝑦 − 𝑦)
Y 1 4 3.2 -0.4 0.4
D ependent
Variable 2 3 3.1 -0.5 -0.6
5 3 4 3.0 -0.6 0.4
4 2 2.9 -0.7 -1.6
4 L ine of Regression
5 5 2.8 -0.8 1.4
1 𝛴 𝑦𝑝 − 𝑦
2
𝑅2 =
X I ndependent 𝛴 𝑦−𝑦 2
Variable
0 1 2 3 4 5 6
www.intellipaat.com
Goodness of Fit – 𝑹𝟐
𝑦𝑝 (𝑦𝑝 − 𝑦) (𝑦 − 𝑦) 𝑦𝑝 − 𝑦
2
2
Y
D ependent
3.2 -0.4 0.4 −0.4
Variable 3.1 -0.5 -0.6
5 3.0 -0.6 0.4
L ine of Regression
2.9 -0.7 -1.6
4
2.8 -0.8 1.4
1 𝛴 𝑦𝑝 − 𝑦
2
𝑅2 =
X I ndependent 𝛴 𝑦−𝑦 2
Variable
0 1 2 3 4 5 6
www.intellipaat.com
Goodness of Fit – 𝑹𝟐
𝑦𝑝 (𝑦𝑝 − 𝑦) (𝑦 − 𝑦) 𝑦𝑝 − 𝑦
2
1 𝛴 𝑦𝑝 − 𝑦
2
𝑅2 =
X I ndependent 𝛴 𝑦−𝑦 2
Variable
0 1 2 3 4 5 6
www.intellipaat.com
Goodness of Fit – 𝑹𝟐
𝑦𝑝 (𝑦𝑝 − 𝑦) (𝑦 − 𝑦) 𝑦𝑝 − 𝑦
2
𝑦 −𝑦 2
2
Y 3.2 -0.4 0.4 0.16 0.4
D ependent
Variable 3.1 -0.5 -0.6 0.25
5 3.0 -0.6 0.4 0.36
2.9 -0.7 -1.6 0.49
4 L ine of Regression
1 𝛴 𝑦𝑝 − 𝑦
2
𝑅2 =
X I ndependent 𝛴 𝑦−𝑦 2
Variable
0 1 2 3 4 5 6
www.intellipaat.com
Goodness of Fit – 𝑹𝟐
𝑦𝑝 (𝑦𝑝 − 𝑦) (𝑦 − 𝑦) 𝑦𝑝 − 𝑦
2
𝑦 −𝑦 2
1 𝛴 𝑦𝑝 − 𝑦
2
𝑅2 =
X I ndependent 𝛴 𝑦−𝑦 2
Variable
0 1 2 3 4 5 6
www.intellipaat.com
Goodness of Fit – 𝑹𝟐
𝑦𝑝 (𝑦𝑝 − 𝑦) (𝑦 − 𝑦) 𝑦𝑝 − 𝑦
2
𝑦 −𝑦 2
3 𝛴 1.9
𝛴 5.2
𝑅 2
=
𝛴 𝑦𝑝 − 𝑦
2
=
1.9
1 𝛴 𝑦−𝑦 2 5.2
X I ndependent
Variable
0 1 2 3 4 5 6
www.intellipaat.com
Goodness of Fit – 𝑹𝟐
𝑦𝑝 (𝑦𝑝 − 𝑦) (𝑦 − 𝑦) 𝑦𝑝 − 𝑦
2
𝑦 −𝑦 2
3 𝛴 1.9
𝛴 5.2
𝑅2 =
𝛴 𝑦𝑝 − 𝑦
2
= 0.36
1 𝛴 𝑦−𝑦 2
X I ndependent
Variable
0 1 2 3 4 5 6
www.intellipaat.com
Goodness of Fit – 𝑹𝟐
4 L ine of Regression
𝑅2 ≈ 0.6
3
X I ndependent
Variable
0 1 2 3 4 5 6
www.intellipaat.com
Goodness of Fit – 𝑹𝟐
4 L ine of Regression
𝑅2 ≈ 0.9
X I ndependent
Variable
0 1 2 3 4 5 6
www.intellipaat.com
Goodness of Fit – 𝑹𝟐
4 𝑅2 ≈ 1
L ine of Regression
I ndependent
Variable
X
0 1 2 3 4 5 6
www.intellipaat.com
www.intellipaat.com
India : +91-7847955955
www.intellipaat.com