Introduction to machine learning through linear regression implementation.
This project implements a linear regression algorithm from scratch to predict car prices based on mileage. It demonstrates fundamental machine learning concepts including gradient descent and data normalization.
- Training program (
train.py): Learns the relationship between mileage and price - Prediction program (
predict.py): Predicts car prices based on trained model - Data visualization with regression line
- Gradient descent optimization
- Model persistence (saves theta values)
train.py: Training algorithm implementationpredict.py: Price prediction using trained modeldata.csv: Training dataset (mileage, price)theta.json: Saved model parametersregression.png: Visualization of the regression linerequirements.txt: Python dependencies
- Python: Programming language
- NumPy: Numerical computations
- Matplotlib: Data visualization
- Pandas: Data manipulation (if used)
python train.pyThis reads data.csv, trains the model using gradient descent, and saves parameters to theta.json.
python predict.pyEnter a mileage value to get a price prediction based on the trained model.
The project implements the linear regression formula:
price = θ₀ + θ₁ × mileage
Using gradient descent to minimize the cost function and find optimal θ values.
- Understanding linear regression fundamentals
- Implementing gradient descent from scratch
- Data normalization techniques
- Model evaluation and visualization
- Machine learning workflow (train/predict)