Welcome to Linear Regression with Gradient Descent, a Rust-based project designed to make linear regression approachable and visually stunning! Whether youβre a data science enthusiast or a Rustacean, this project has something for you.
This repository implements a linear regression model using gradient descent. It includes:
- Trainer: Train the model with your dataset.
- Predictor: Use the trained model to predict values.
- GUI: Visualize the data, regression line, and gradient descent process interactively.
- Linear Regression: library to handle linear regression stuff.
- Gradient Descent: Train the model iteratively.
- Interactive GUI: Adjust settings, visualize plots, and watch gradient descent in action.
- Makefile Integration: Simplify build and execution workflows.
- Environment Configuration: Store paths and configurations in a
.envfile.
Hereβs the project layout:
. βββ Cargo.lock # Dependency lock file βββ Cargo.toml # Workspace configuration βββ data # Data folder β βββ data.csv # Dataset for training β βββ theta.txt # Model parameters (theta0, theta1) βββ gui # GUI application β βββ Cargo.toml β βββ src β βββ app.rs # Main application logic β βββ components # Reusable UI components β β βββ mod.rs β β βββ navbar.rs β β βββ plane.rs β β βββ sidebar.rs β βββ main.rs # GUI entry point β βββ settings # Settings modules β β βββ grid_settings.rs β β βββ mod.rs β β βββ plot_settings.rs β β βββ sidebar_settings.rs β βββ utils.rs # Helper functions βββ linear_regression # Core library for regression logic β βββ Cargo.toml β βββ src β βββ lib.rs β βββ linear_regression.rs β βββ utils.rs βββ Makefile # Build and execution shortcuts βββ predictor # Predictor application β βββ Cargo.toml β βββ src β βββ main.rs # Entry point for predictions βββ README.md # This file! βββ trainer # Trainer application β βββ Cargo.toml β βββ src β βββ main.rs # Entry point for training To keep things clean and configurable, the project uses a .env file. Make sure to create it in the root directory:
THETA_PATH=data/theta.txt DATASET_PATH=data/data.csv - THETA_PATH: Path to the file where model parameters (theta0, theta1) are stored.
- DATASET_PATH: Path to the CSV file containing your dataset.
The Makefile simplifies building and running the project. Hereβs what you can do:
make buildmake predictormake trainermake guimake webmake clean- Ensure
data/data.csvcontains your dataset (e.g., mileage vs. price). - Run the trainer:
make trainer
- The trained parameters will be saved to
data/theta.txt.
- Use the predictor to estimate values based on the trained model:
make predictor
- Enter a mileage value when prompted, and the program will output the estimated price.
- Run the GUI:
make gui # or make web - Explore your dataset, adjust parameters, and watch the regression line and gradient descent come to life!
Your data/data.csv should look like this:
mileage,price 5000,20000 10000,18000 15000,16000 20000,14000 25000,12000 Contributions are welcome! Feel free to open issues or submit pull requests to enhance the project.
Enjoy using Linear Regression with Gradient Descent! π Let me know if you have any feedback or feature requests.



