A Python module for the generation and training of an entry-level feedforward neural network.
This repository serves as a repurposing of a 2019 project I did as an initiation into machine learning.
Creating a network:
network = Network(layer_sizes, bias_value)
layer_sizes: Number of neurons in each layer.
Ex: [2, 5, 1] will generate a network that can be visualized as such:
bias_value: Value of the bias nodes (standardized at 1):
Bias nodes are added to a feed-forward neural network to help facilitate
learning patterns. They function like an input node that always
produces a value of 1.0 or other constant.
- Initializes the weights between all neurons with a random value.
network.train(input_data, target_data, learning_rate)
input_data: The input data, a good approach is to have it normalized into a proper range.
target_data: The data that the model learns from.
learning_rate: Controls how quickly or slowly the network model learns the problem.
For an (output = X) pattern learning data:
Which should lead to:
from network import Network from data_set import DataSet # Initializing a network with a 2-2-1 structure network = Network([2, 2, 1], 1.0) # Randomizing initial weights between all neurons network.randomize() # Initializing data_set with input and output training data inputs = [[0, 1], [1, 0], [1, 1]] outputs = [, , ] data_set = DataSet(inputs, outputs) # Training the network for 10000 intervals for _ in range(10000): for index in range(0, data_set.get_size()): network.train(data_set.get_input(index),data_set.get_target(index), 1.0) # Printing output prediction for input = [0, 0] print(network.calculate_outputs([0, 0]))
We get :
output : [0.0023672395614975253]