Suppose we are given a dataset
Given is a Work vs Experience dataset of a company and the task is to predict the salary of a employee based on his / her work experience.
This article aims to explain how in reality Linear regression mathematically works when we use a predefined function to perform prediction task.
Let us explore how the stuff works when Linear Regression algorithm gets trained.
.
Iteration 1 – In the start, θ_{0} and θ_{1} values are randomly choosen. Let us suppose, θ_{0} = 0 and θ_{1} = 0.

Predicted values after iteration 1 with Linear regression hypothesis.

Cost Function – Error

Gradient Descent – Updating θ_{0} value
Here, j = 0

Gradient Descent – Updating θ_{1} value
Here, j = 1

Predicted values after iteration 1 with Linear regression hypothesis.
 ML  Linear Regression vs Logistic Regression
 ML  Mathematical explanation of RMSE and Rsquared error
 ChiSquare Test for Feature Selection  Mathematical Explanation
 Linear Regression (Python Implementation)
 Multiple Linear Regression using R
 Linear Regression using PyTorch
 Simple LinearRegression using R
 Linear Regression Using Tensorflow
 ML  Linear Regression
 Gradient Descent in Linear Regression
 ML  Boston Housing Kaggle Challenge with Linear Regression
 ML  Normal Equation in Linear Regression
 ML  Locally weighted Linear Regression
 ML  Multiple Linear Regression using Python
 ML  Rainfall prediction using Linear regression
 A Practical approach to Simple Linear Regression using R
 Python  Linear Regression using sklearn
 Univariate Linear Regression in Python
 Pyspark  Linear regression using Apache MLlib
 ML  Multiple Linear Regression (Backward Elimination Technique)
Iteration 2 – θ_{0} = 0.005 and θ_{1} = 0.02657
Now, similar to iteration no. 1 performed above we will again calculate Cost function and update θ_{j} values using Gradient Descent.
We will keep on iterating until Cost function doesn’t reduce further. At that point, model achieves best θ values. Using these θ values in the model hypothesis will give the best prediction results.
Attention reader! Don’t stop learning now. Get hold of all the important CS Theory concepts for SDE interviews with the CS Theory Course at a studentfriendly price and become industry ready.
Recommended Posts:
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.