Skip to main content

Feed Forward Neural Networks

Project description

Feed Forward Neural Networks using NumPy

This library is a modification of my previous one. Click Here to check my previous library.

Installation

$ [sudo] pip3 install neuralnetworks-shine7

Development Installation

$ git clone https://github.com/Subhash3/Neural_Net_Using_NumPy.git

Usage

>>> from Model import NeuralNetwork

Creating a Neural Network

inputs = 2
outputs = 1
network = NeuralNetwork(inputs, outputs)

# Add 2 hidden layers with 16 neurons each and activation function 'tanh'
network.addLayer(16, activation_function="tanh") 
network.addLayer(16, activation_function="tanh")

# Finish the neural network by adding the output layer with sigmoid activation function.
network.compile(activation_function="sigmoid")

Building a dataset

The package contains a Dataset class to create a dataset.

>>> from Model import Dataset

Make sure you have inputs and target values in seperate files in csv format.

input_file = "inputs.csv"
target_file = "targets.csv"

# Create a dataset object with the same inputs and outputs defined for the network.
datasetCreator = Dataset(inputs, outputs)
datasetCreator.makeDataset(input_file, target_file)
data, size = datasetCreator.getRawData()

If you want to manually make a dataset, follow these rules:

  • Dataset must be a list of data samples.
  • A data sample is a list containing inputs and target values.
  • Input and target values are column vector of size (inputs x 1) and (outputs x 1) respectively.

For eg, a typical XOR data set looks something like :

>>> XOR_data = [
    [
        np.array([[0], [0]]),
        np.array([[0]])
    ],
    [
        np.array([[0], [1]]),
        np.array([[1]])
    ],
    [
        np.array([[1], [0]]),
        np.array([[1]])
    ],
    [
        np.array([[1], [1]]),
        np.array([[0]])
    ]
]
>>> size = 4

Training The network

The library provides a Train function which accepts the dataset, dataset size, and two optional parameters epochs, and logging.

def Train(dataset, size, epochs=5000, logging=True) :
	....
	....

For Eg: If you want to train your network for 1000 epochs.

>>> network.Train(data, size, epochs=1000)

Notice that I didn't change the value of log_outputs as I want the output to printed for each epoch.

Debugging

Plot a nice epoch vs error graph

>>> network.epoch_vs_error()

Know how well the model performed.

>>> network.evaluate()

To take a look at all the layers' info

>>> network.display()

Sometimes, learning rate might have to be altered for better convergence.

>>> network.setLearningRate(0.1)

Exporting Model

You can export a trained model to a json file which can be loaded and used for predictions in the future.

filename = "model.json"
network.export_model(filename)

Load Model

To load a model from an exported model (json) file. load_model is a static function, so you must not call this on a NeuralNetwork object!.

filename = "model.json"
network = NeuralNetwork.load_model(filename)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

neuralnetworks-shine7-0.0.11.tar.gz (7.6 kB view details)

Uploaded Source

Built Distribution

neuralnetworks_shine7-0.0.11-py3-none-any.whl (7.9 kB view details)

Uploaded Python 3

File details

Details for the file neuralnetworks-shine7-0.0.11.tar.gz.

File metadata

  • Download URL: neuralnetworks-shine7-0.0.11.tar.gz
  • Upload date:
  • Size: 7.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.6.9

File hashes

Hashes for neuralnetworks-shine7-0.0.11.tar.gz
Algorithm Hash digest
SHA256 1b3764acd9596d2b94e931370bdec264ecee139011bc8601386e06577348f108
MD5 21d7a0b0560cc83bd3fc5d0e8fc14d43
BLAKE2b-256 afdac15cef681e8c9ceabea2c7b68cca5a29a08078d4aac17ff5cdf356bc5664

See more details on using hashes here.

File details

Details for the file neuralnetworks_shine7-0.0.11-py3-none-any.whl.

File metadata

  • Download URL: neuralnetworks_shine7-0.0.11-py3-none-any.whl
  • Upload date:
  • Size: 7.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.6.9

File hashes

Hashes for neuralnetworks_shine7-0.0.11-py3-none-any.whl
Algorithm Hash digest
SHA256 3abdeeeeddc447de067cbeef90e2b84f34e6e8127a4b66daac44afff484e8ee0
MD5 3df775371c0236f0aa174249b12a9868
BLAKE2b-256 ac50ea0ec43de8b7487f4f138d26eecf8bb43ff1478d3db25efcdd894d86719b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page