Lecture 4 - Multiple Linear Regression Imran 20022025 092939am
Lecture 4 - Multiple Linear Regression Imran 20022025 092939am
Regression
Introduction to Machine Learning
Contents
1. What is multiple linear regression (MLR)
• … = do the same for however many independent variables you are testing
• A = 7, 2, 9, 8 and
• B = 1, 2, 3, 4?
• Prior knowledge (Data domain expert) tell you which features to keep and
which to discard
Backward Elimination
1. Select a significance level (SL) for P-value e.g. 5% (0.05)
5. Fit model without the variable and go to step 3 if all features have not
been exhausted. Otherwise terminate
Forward selection
Select Select a significance level (SL) for P-value e.g. 5% (0.05)
Fit Fit all the predictors y->xn one at a time and select one with the lowest P-value
Keep Keep this variable and fit all possible models with one extra predictor i.e., add one
predictor to the variables you already have.
Consider Consider the predictor with the least P-value. If P<SL, go to step 3, otherwise finish.
(keep the previous model)
Select a significance level to enter (SL_Enter) and
stay (SL_stay) in the model.
Python Implementation
Importing
Dataset
Dataset
• Total 50 samples
• 80, 20 split
Training and testing the model
Evaluating the model
Q: Do we need to normalize the data in MLR
•A: No, we do not need to perform normalization for MLR, since
the coefficients b0, b1, b2,… in the MLR model automatically
does that.
to •A: Absolutely not, for a new dataset play and experiment with
it. If there are redundant features it will perform poorly.
5. Fit model without the variable and go to step 3 if all features have not
been exhausted. Otherwise terminate
Code
• Importing the dataset
• Dividing the dataset into independent and dependent varia
• One hot encoding for the categorical data
• We do not need to cater the missing values as there are non
Inserting beta_0
2. Fit all the predictors y->xn one at a time and select one with the lowest
P-value
3. Keep this variable and fit all possible models with one extra predictor i.e.,
add one predictor to the variables you already have.