This repository contains a basic neural network implementation in Python using NumPy. The neural network is designed with customizable layers for flexibility in building different architectures. I also created a tutorial about how to create a Neural Network from scratch and how it's math works: Tutorial
- Clone the repository to your local machine:
git clone https://github.com/valteu/basic-neural-network.git
Navigate to the project directory:
cd basic-neural-network
Ensure you have NumPy and matplotlib installed. You can install them using pip:
pip install numpy matplotlib
You are now ready to use the Basic Neural Network.
You can use this basic neural network implementation in your Python projects by following these steps:
- Import the necessary modules:
import numpy as np
from Layer import Layer, Linear, ReLu, Sigmoid
from Network import Network
-
Create a neural network architecture by instantiating different layers (Linear, ReLu, Sigmoid) and specifying the input and output dimensions.
-
Initialize the network with the desired architecture, and optionally provide weights and biases for the layers.
-
Train the network by providing your data and targets using the train method, specifying the number of epochs and learning rate.
-
Test the network on new data using the test method.
-
Save the learned weights and biases to a JSON file for later use, if needed.
The neural network architecture consists of the following key components:
-
Layer: A base class for defining the structure of each layer in the network. You can derive custom layer types from this class.
-
Linear: A fully connected layer that performs a linear transformation.
-
ReLu: A rectified linear unit (ReLU) activation layer.
-
Sigmoid: A sigmoid activation layer.
-
Network: The main class for building and training the neural network. It allows you to specify the network architecture and perform forward and backward passes.
An example script is provided in the main.py file to demonstrate how to use this neural network for regression tasks. It generates random 1D data and targets, creates a network with a simple architecture, trains the network, and tests it on new data.
To run the example, execute the following command:
python main.py
This script can be easily adapted for your specific use cases and data.
License This project is licensed under the MIT License.