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
.env
file.
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 build
make predictor
make trainer
make gui
make web
make clean
- Ensure
data/data.csv
contains 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.