A Simple Neural Network from scratch

A Simple Neural Network from scratch in Python using the Pymathrix library.
Check the Pymathrix documentation.

Usage

Import the Pymathrix library into your python code:

>>> import pymathrix as px

Create the input data matrix:

>>> inputs = px.matrix(1, 3)
>>> inputs.assign([1, 1, -1])

Create the neural network object:

>>> snn = simple_neural_network(3, 4, 2, 0.7) # this creates a neural network with 3 input neurons, 4 hidden neurons, 2 output neurons and a learning rate of 0.7

Make a fisrt guess from the neural network by performing a feedforward:

>>> first_guess = snn.feedforward(inputs)
>>> print(f"guess before training:\n{first_guess}")
|  0.61  |
|   0.5  |

Let us now train our neural network:

>>> outputs = px.matrix(1, 2)
>>> outputs.assign([1, 1])
>>> snn.train(inputs, outputs, 500) # 500 is the number of epochs (number of times to loop through the entire training dataset)

Now let us now make a second guess after the training process:

>>> second_guess = snn.feedforward(inputs)
>>> print(f"guess after training:\n{second_guess}")
|  0.98  |
|  0.98  |

GitHub

View Github