This repository contains Python code for implementing linear regression using gradient descent. Regards to Andrew NG for his course on machine learning
Linear regression is a powerful statistical method that models the relationship between a dependent variable and one or more independent variables. It's widely used in various fields such as economics, finance, and machine learning for tasks like predicting house prices, stock prices, and more.
This code implements linear regression and gradient descent from scratch using NumPy, a popular library for numerical computing in Python. The implementation includes functions to calculate the cost, gradients, and update weights and biases using gradient descent.
- Input Data: Provide training data
x_train
and corresponding labelsy_train
. These represent the features (independent variables) and target variable (dependent variable) respectively. - Set Parameters: Set initial values for weights
w
and biasb
, learning ratea
, and number of iterationsitr
. - Run Code: Execute the
finalfunc
function with the provided inputs. This function applies gradient descent to find the optimal parameters for the linear regression model. - Prediction: Input the area of a house to predict its selling price. The model will output the predicted selling price based on the learned parameters.
linear_regression.py
: Python script containing the implementation of linear regression and gradient descent.README.md
: This file providing an overview of the repository and instructions for usage.
To use this code, follow these steps:
- Clone the repository to your local machine.
- Install the required dependencies (Python 3 and NumPy).
- Open
linear_regression.py
and provide your training data (x_train
andy_train
). - Set the initial values for weights
w
and biasb
, learning ratea
, and number of iterationsitr
. - Run the script and observe the output.
- Use the
finalfunc
function to make predictions for new data.
- Python 3
- NumPy
This project is licensed under the MIT License - see the LICENSE file for details.
- This implementation was inspired by Andrew Ng's Machine Learning course on Coursera.
- Special thanks to the open-source community for their contributions to NumPy and other libraries used in this project.