International Journal of Computer Applications |
Foundation of Computer Science (FCS), NY, USA |
Volume 186 - Number 9 |
Year of Publication: 2024 |
Authors: Ahmad Farhan AlShammari |
10.5120/ijca2024923446 |
Ahmad Farhan AlShammari . Implementation of Linear Regression using Least Squares and Gradient Descent in Python. International Journal of Computer Applications. 186, 9 ( Feb 2024), 52-57. DOI=10.5120/ijca2024923446
The goal of this research is to develop a linear regression program using least squares and gradient descent in Python. Linear regression helps to find the line that best fits to the data points. The linear regression model is based on a linear polynomial of slope (m) and intercept (c). Least squares is used to minimize the error between the observed and predicted points. Gradient descent is used to find the optimal solution that provides the minimum value of error function. The basic steps of linear regression using least squares and gradient descent are explained: preparing observed points, initializing slope and intercept, computing predicted points, computing partial derivatives, updating slope and intercept, computing error function, making equation of line, and plotting predicted line. The developed program was tested on an experimental dataset from Kaggle. The program successfully performed the basic steps of linear regression and provided the required results.