Lecture - 2 Linear Regression (Applied ML)
Lecture - 2 Linear Regression (Applied ML)
● Sales forecasting
● Satisfaction analysis
● Price estimation
● Employment Income
Linear Regression with one variable
Model Representation
Linear regression with one variable
We want to tell the price of the house given the size of the house?
Linear regression with one variable
Linear regression with one variable
Linear regression with one variable
Linear regression with one variable
Linear regression with one variable
Linear regression with one variable
Linear regression with one variable
Linear regression with one variable
Linear Regression with one variable
Gradient descent
Gradient Descent in Linear Regression?
● Any ML project our main aim relies on how good our project accuracy is or how much our
model prediction differs from the actual data point.
● Based on the difference between model prediction and actual data points we try to find the
parameters of the model which give better accuracy on our dataset
● In order to find these parameters we apply gradient descent on the cost function of the
machine learning model.
Gradient Descent in Linear Regression?
Gradient Descent in Linear Regression?
Gradient descent
Gradient descent
Gradient descent - learning rate
Multiple features
Single Variable vs multiple variables
Modeling
Modeling
Learning rate
Learning rate
Learning rate
Linear Regression with Python
Given Boston house prices dataset: Mock Scenario
● Imagine the following scenario: Your team has been contracted by a real-estate company who owns
many houses in the Boston metro-area. You are tasked to analyze if the house prices owned by the
company are competitive and if they need to be adjusted to optimize the overall profit.
Below are some questions that your team might want to address before making recommendations:
● Is there a relationship between the different predictors/features and the house prices
● If there is such a relationship, then how strong is it?
● Which features affect the most the house prices?
● How accurately can we estimate the effect of each feature to the house prices?
● How accurately can we predict the house prices based on these features?
● What kind of relationship is there between the features and the house prices? Linear?Non-linear?
● Is there any interaction effect among the features?
● Many of the measurements are in different scale - It is important to scale the data before we fit a
linear regression.
Scaling data
Train-Test Split
Fitting the Model
Now that we have fitted our model, we can actually go ahead and extract the estimated coefficients,
including the intercept
22.605596398342957
Now that our model is fit, we need to assess the performance of our model by testing it on the test-set.
lg_r2=r2_score(y_test,lg_pred)
mse=mean_squared_error(y_test,lg_pred)
lg_r2
mse