Multiple Linear Regression (MLR)

 

 Multiple Linear Regression (MLR)


🔹 Introduction

Multiple Linear Regression is an extension of simple linear regression where:

👉 We use more than one input variable (feature) to predict a single continuous output.

It models the relationship between one dependent variable and two or more independent variables

In real-world problems the response variable is often influenced by multiple predictors

🔹 Problem Formulation

Given dataset:

D={(xi1,xi2,...,xip,yi)}D = \{(x_{i1}, x_{i2}, ..., x_{ip}, y_i)\}
  • xij → j-th feature
  • yiy_i → output

🔹 Model Representation (Hypothesis)

y=β0+β1x1+β2x2++βpxpy = \beta_0 + \beta_1 x_1 + \beta_2 x_2 + \cdots + \beta_p x_p

Where:

  • β0\beta_0→ intercept
  • βj\beta_j→ coefficient of feature xjx_j

👉 This is a linear combination of inputs


🔹Example

📌 House Price Prediction

Features:

  • x1x_1 → area
  • x2x_2 → number of rooms
  • x3x_3 → location score

Model:

Price=β0+β1(area)+β2(rooms)+β3(location)\text{Price} = \beta_0 + \beta_1(\text{area}) + \beta_2(\text{rooms}) + \beta_3(\text{location})

🔹Objective Function

We minimize squared error:

J(β)=(yiy^i)2J(\beta) = \sum (y_i - \hat{y}_i)^2

👉 Same as simple regression but with multiple variables

🔹Dataset Representation

Assume:

  • nn observations
  • pp features

📌 Feature Matrix XX (size n×p)

X=[x11x12x1px21x22x2pxn1xn2xnp]X = \begin{bmatrix} x_{11} & x_{12} & \cdots & x_{1p} \\ x_{21} & x_{22} & \cdots & x_{2p} \\ \vdots & \vdots & \ddots & \vdots \\ x_{n1} & x_{n2} & \cdots & x_{np} \end{bmatrix}


📌 Response Vector yy

y=[y1y2yn]y = \begin{bmatrix} y_1 \\ y_2 \\ \vdots \\ y_n \end{bmatrix}


🔹 Regression Model

For pp features:

yi=β0+β1xi1+β2xi2++βpxipy_i = \beta_0 + \beta_1 x_{i1} + \beta_2 x_{i2} + \cdots + \beta_p x_{ip}


🔹 Matrix Form (Very Important)

Add a column of 1s for intercept:

X=[1x11x12x1p1x21x22x2p1xn1xn2xnp]X = \begin{bmatrix} 1 & x_{11} & x_{12} & \cdots & x_{1p} \\ 1 & x_{21} & x_{22} & \cdots & x_{2p} \\ \vdots & \vdots & \vdots & \ddots & \vdots \\ 1 & x_{n1} & x_{n2} & \cdots & x_{np} \end{bmatrix}


📌 Parameter Vector

β=[β0β1βp]\beta = \begin{bmatrix} \beta_0 \\ \beta_1 \\ \vdots \\ \beta_p \end{bmatrix}


📌 Model Equation

y=Xβy = X\beta


🔹 Least Squares Solution

We estimate parameters using:

β^=(XTX)1XTy\hat{\beta} = (X^T X)^{-1} X^T y

👉 This is called the Normal Equation


🔹  Final Prediction

y^=Xβ^\hat{y} = X\hat{\beta}


🔹 Important Notes

  • Requires all data in memory
  • Uses matrix operations
  • Efficient for small to medium datasets

🔹 How It Works (Step-by-Step)

  1. Represent data in matrix form
  2. Define hypothesis
  3. Compute error (MSE)
  4. Minimize error
  5. Estimate coefficients

🔹 Geometric Interpretation

  • 1 variable → line
  • 2 variables → plane
  • many variables → hyperplane

🔹Assumptions 

  1. Linearity
  2. Independence of errors
  3. Constant variance (Homoscedasticity)
  4. No multicollinearity
  5. Normal distribution of errors

🔹 Applications

📊 Real-world examples:

  • House price prediction
  • Stock price prediction
  • Medical diagnosis
  • Sales forecasting
  • Risk analysis

🔹Advantages

  • Handles multiple factors
  • More accurate than simple regression
  • Interpretable coefficients

🔹 Limitations

  • Sensitive to multicollinearity
  • Assumes linear relationship
  • Can overfit with many features

🔹 Comparison

Feature    Simple LRMultiple LR
Inputs    One    Multiple
Model    Line    Plane/Hyperplane
Complexity    Low    Higher

📘 Worked Example


🔹 Given Data

X1X_1X2X_2YY
1        1    3.25
12    6.5
22    3.5
01    5

🔹 Step 1: Construct Matrix XX

X=[111112122101]X = \begin{bmatrix} 1 & 1 & 1 \\ 1 & 1 & 2 \\ 1 & 2 & 2 \\ 1 & 0 & 1 \end{bmatrix}


🔹 Step 2: Compute XTXX^T X

XTX=[4464676710]X^T X = \begin{bmatrix} 4 & 4 & 6 \\ 4 & 6 & 7 \\ 6 & 7 & 10 \end{bmatrix}


🔹 Step 3: Compute Inverse

(XTX)1=[2.750.520.511212](X^T X)^{-1} = \begin{bmatrix} 2.75 & 0.5 & -2 \\ 0.5 & 1 & -1 \\ -2 & -1 & 2 \end{bmatrix}


🔹 Step 4: Compute XTy

XTy=[18.2516.7528.25]X^T y = \begin{bmatrix} 18.25 \\ 16.75 \\ 28.25 \end{bmatrix}


🔹 Step 5: Compute Coefficients

β^=[2.06252.3753.25]\hat{\beta} = \begin{bmatrix} 2.0625 \\ -2.375 \\ 3.25 \end{bmatrix}


✅ Final Regression Model

y^=2.06252.375x1+3.25x2\hat{y} = 2.0625 - 2.375x_1 + 3.25x_2



📝 Summary (Quick Revision)

👉 Real-world problems depend on multiple variables, so:

Multiple regression is more practical than simple regression


  • Model:

y=Xβy = X\beta

  • Solution:

β^=(XTX)1XTy\hat{\beta} = (X^T X)^{-1} X^T y

  • Prediction:

y^=Xβ^\hat{y} = X\hat{\beta}

Comments

Popular posts from this blog

Machine Learning PCCST503 Semester5 KTU CS 2024 Scheme - Dr Binu V P

Introduction to Machine Learning (ML)

Distinguishing Machine Learning from Traditional Programming