Skip to content

Param302/ScratchNet

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Overview

ScratchNet is a demonstration of building and training Artificial Neural Networks (ANNs) from scratch in Python using only NumPy - no deep learning frameworks. The models are trained on classic datasets and this app showcases their performance and predictions interactively.

ScratchNet.mp4

Datasets

Breast Cancer (Binary Classification)

Classifies tumors as benign or malignant using 30 features from digitized images of fine needle aspirate (FNA) of breast mass.
Target labels: Benign (0), Malignant (1).
Dataset: scikit-learn's Breast Cancer Wisconsin.

California Housing (Regression)

Predicts the median house value in a California block group using 8 features such as median income, house age, average rooms, and location.
Target label: MedHouseVal (Median House Value).
Dataset: scikit-learn's California Housing.

Iris Flower Species (Multiclass Classification)

Predicts the species of an iris flower using four features: sepal length, sepal width, petal length, and petal width.
Target labels: Setosa, Versicolor, Virginica.
Dataset: scikit-learn's Iris.


Models

Model Architecture

Breast Cancer
  • 4 layers:
    • Input: 30 features
    • Hidden: 30, 60, 15 neurons
    • Output: 1 (Sigmoid)
  • Activations: ReLU, Sigmoid
  • Loss: Binary Cross Entropy
  • Accuracy: 89%
    View Model Code
California Housing
  • 5 layers:
    • Input: 8 features
    • Hidden: 10, 16, 32, 16 neurons
    • Output: 1 (Linear)
  • Activations: ReLU, Linear
  • Loss: MSE
    View Model Code
Iris
  • 5 layers:
    • Input: 4 features
    • Hidden: 8, 16, 64, 10 neurons
    • Output: 3 (Softmax)
  • Activations: ReLU, Softmax
  • Loss: Sparse Categorical Cross Entropy
  • Accuracy: 97%
    View Model Code

Neural Network Module

The neural network, dense layers, loss, and activation functions are implemented from scratch in the NN/ directory:

  • network.py: Neural network class, training loop, prediction, summary, save/load.
  • layers.py: Dense layer implementation.
  • activations.py: ReLU, Sigmoid, Softmax, Linear, Tanh.
  • loss.py: MSE, Binary Cross Entropy, Sparse Categorical Cross Entropy.

View NN Module


Model Notebook

All model development, training, and analysis are documented in
ANN_from_Scratch.ipynb.


Steps to Run

Requires:

  • Python 3.10.16
  • Streamlit 1.46.0
  1. Clone the repository

    git clone https://github.com/Param302/ScratchNet.git
    cd ScratchNet
    
  2. Create a virtual environment

    • Windows
      python -m venv venv
      venv\Scripts\activate
      
    • Linux/Mac
      python3 -m venv venv
      source venv/bin/activate
      
  3. Install requirements

    pip install -r requirements.txt
    
  4. Run the Streamlit app

    streamlit run app/main.py
    

    OR

    Run each model script directly to train the model

    python models/code/ANN_Breast_cancer.py
    python models/code/ANN_California_housing.py
    python models/code/ANN_iris.py
    

Contact

For any questions or contributions, feel free to reach out:
Parampreet Singh Email: connectwithparam.30@gmail.com


About

This app demonstrates custom-built Neural Networks implemented from scratch in Python using only NumPy.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published