Skip to content

shreyaph16/Regression-Model-Using-Micrograd

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

4 Commits
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿงฎ Regression Model Using a Custom Autodiff Engine

This project demonstrates the implementation of a simple linear regression model built entirely from scratch, utilizing the core concepts of a lightweight autodifferentiation engine inspired by micrograd.

The goal is to train a model to uncover a hidden linear relationship within noisy, synthetically generated data.


๐Ÿ“‚ File Breakdown

File Name Purpose Description
Parabolic_micrograd.py Core Autodiff Engine (Primitives) Contains the foundational components for building the neural network structure, including the custom Value class. Defines basic mathematical operations (addition, multiplication, power, etc.) and their corresponding gradient calculation logic for the backward pass.
Regression_model_micrograd.py Application and Training Loop Implements the complete end-to-end regression pipeline, including:
1๏ธ Data Generation โ€“ creates parabolic data with noise.
2๏ธ LinearModel Class โ€“ defines the regression model.
3๏ธ Loss Function โ€“ Mean Squared Error (MSE).
4๏ธ Training Loop โ€“ performs gradient descent for parameter optimization.

๐Ÿš€ How It Works

  1. Generate synthetic data with an underlying parabolic relationship and added random noise.
  2. Define a linear model with parameters (w, b) represented as custom Value objects.
  3. Compute the loss using Mean Squared Error (MSE).
  4. Backpropagate gradients through the computation graph using the custom autodiff engine.
  5. Update parameters via manual gradient descent steps.

๐Ÿงฉ Key Concepts Demonstrated

  • Building a minimal autodifferentiation system from scratch
  • Implementing a computation graph and backward propagation manually
  • Training a model using gradient-based optimization

๐Ÿ› ๏ธ Requirements

  • Python 3.8+
  • Makes use of libraries like numpy, pandas, matplotlib and graphviz

๐Ÿ“ˆ Example Output

After training, the model learns to approximate the hidden relationship between x and y, reducing the mean squared error significantly over time.


๐Ÿ“œ License

This project is released under the MIT License.


Author: Shreya
Inspired by: Andrej Karpathyโ€™s micrograd

About

By making use of micrograd, I create a regression model on a parabolic function

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages