Python implementation of multilayer perceptron neural network from scratch.
Project description
Multilayer Perceptron in Python
Python implementation of multilayer perceptron neural network from scratch.
Minimal neural network class with regularization using scipy minimize. Contains clear pydoc for learners to better understand each stage in the neural network.
Requirements
Python 3.4 (tested)
Goal
To provide an example of a simple MLP for educational purpose.
Code sample
Predicting outcome of AND logic gate:
- X = 000, 001, 010, 011, 100, 101, 110, 111
y = 0,0,0,0,0,0,1
Data we want to predict: p = 011, 111, 000, 010, 111 Expected results are: 0, 1, 0, 0, 1
import numpy as np
from mlperceptron.mlperceptron import NeuralNetwork
X = np.matrix(
'0 0 0;0 0 1;0 1 0;0 1 1;1 0 0;1 0 1;1 1 0;1 1 1')
y = np.matrix('0;0;0;0;0;0;0;1')
n = NeuralNetwork((5,5,))
g = n.train(X, y, 0.01, show_cost=True)
y_pred = n.predict(np.matrix('0 1 1;1 1 1;0 0 0;0 1 0;1 1 1'), g)
print(y_pred)
print(n.accuracy(y_pred, np.matrix('0;1;0;0;1')))
Contributors
Paulo Kuong (@pkuong)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
mlperceptron-0.3.tar.gz
(5.7 kB
view details)
File details
Details for the file mlperceptron-0.3.tar.gz
.
File metadata
- Download URL: mlperceptron-0.3.tar.gz
- Upload date:
- Size: 5.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 593d8ab73b20649d27b1eef061d0f49cc6b876b8cdf40a4fe81cd1c2cb6a68f7 |
|
MD5 | 976f77c88a45064281eb0b3a2ad9f5d2 |
|
BLAKE2b-256 | 18f01542ea0e518eab35644c4b500a962463e9083275f4033d352709a77174cc |