Skip to content

Neural Network From Scratch in Python | Build a simple neural network from scratch using pure Python and NumPy. Learn about forward propagation, backpropagation, and training with gradient descent. Accompanies my Medium article.

Notifications You must be signed in to change notification settings

jkosla/neural_network_from_scratch_numpy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🧠 Neural Network From Scratch in Python

This repository contains the full implementation of a simple neural network built from scratch in Python, as demonstrated in my Medium article.


📖 Overview

In this project, we build a fully connected neural network from scratch without using deep learning libraries like PyTorch or TensorFlow. The implementation includes:

  • Forward Propagation
  • Backpropagation
  • Training with Gradient Descent
  • Evaluation & Accuracy Calculation

The code is designed to be simple and educational, demonstrating the core concepts of neural networks. Perfect for beginners who want to understand how neural networks work under the hood!


📂 Files

  • simple_nn.py — Implementation of the neural network.
  • train.py — Training script with evaluation functions.
  • dataset.py — Helper functions for data processing and evaluation.

💡 Getting Started

Requirements

  • Python 3.x
  • NumPy

Install dependencies:

pip install numpy
pip install matplotlib

Usage:

%matplotlib inline
from dataset import visualize_classification, XORDataset
import matplotlib.pyplot as plt
from simple_nn import SimpleClassifier, GradientDescent
from train_nn import train_model, eval_model, create_data_loader
num_inputs = 2
num_hidden = 4
num_outputs = 1

train_dataset = XORDataset(size=2500)
test_dataset = XORDataset(size=500)

train_data_loader = create_data_loader(train_dataset)
test_data_loader = create_data_loader(test_dataset)


model = SimpleClassifier(num_inputs, num_hidden, num_outputs)
optimizer = GradientDescent(lr=0.01)
_ = visualize_classification(model, test_dataset.data, test_dataset.label)

png

train_model(model, train_data_loader, optimizer)
eval_model(model, test_data_loader)
_ = visualize_classification(model, test_dataset.data, test_dataset.label)
Model Accuracy: 100.00%

png

About

Neural Network From Scratch in Python | Build a simple neural network from scratch using pure Python and NumPy. Learn about forward propagation, backpropagation, and training with gradient descent. Accompanies my Medium article.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published