Hi! This is my 42 cursus project, ft_linear_regression. The objective was to implement the gradient descent algorithm from scratch and use it to train a linear regression model that predict a car price based on its mileage.
Note
To run the program from source, you need to have uv
installed on your system.
https://docs.astral.sh/uv/getting-started/installation/
To train the model
uv run sources/train.py
To make predictions
uv run sources/predict.py
To plot the model
uv run sources/bonus.py
The first step is to define our loss function. Here I am using the Mean Squared Error (MSE) definition.
Note that the factor
Now that we have the loss function, we need to compute the partial derivatives with respect to
Let:
Then by using the chain rule: