Univariate Linear Regression
Explore univariate linear regression to predict an outcome using one independent variable. Understand the regression equation, cost function minimization, and how gradient descent optimizes parameters in machine learning.
Univariate linear regression
In univariate linear regression, we have one independent variable , which we use to predict a dependent variable .
We’ll use the tips dataset from seaborn’s datasets to illustrate theoretical concepts.
We’ll use the following columns from the dataset for univariate analysis:
-
Total_bill: It is the total bill of food served.
-
Tip: It is the tip given on the cost of food.
Goal of univariate linear regression: The goal is to predict the “tip” given on a “total_bill”. The regression model constructs an equation to do so.
If we plot the scatter plot between the independent variable (total_bill) and the dependent variable (tip), we’ll get the plot below:
-
We can see that the points in the scatter plot are mostly scattered along the diagonal.
-
This indicates that there may be a positive correlation between the total_bill and tip. This will be useful for modeling.
Working
The univariate linear regression model comes up with the following equation of the straight line:
Or
Goal: Find the values of and , where and are the parameters, so that the predicted tip () is as close to the actual tip () as possible. Mathematically, we can model the problem as seen below.
=
-
is the cost function, which an algorithm tries to minimize by finding the values of and . These values give us the minimum value of the above function.
-
is the actual output value of a training instance , where
-
...