neural-network
neural-network is a Python package on TestPyPi that provides a Multi-Layer Perceptron (MLP) framework built using only NumPy. The framework supports Gradient Descent, Momentum, RMSProp, and Adam optimizers.
Table of Contents
Installation
Dependencies
python>=3.8
numpy>=1.22.1
matplotlib>=3.5.1
User installation
You can install neural-network using pip:
pip install neural-network
Simple Usage
Designing the Model Architecture
To define your MLP model, you need to specify the number of layers and the number of neurons in each one.
Unless you want to manually set up the parameters, the size of the input layer is not needed, as it will be automatically determined in the initial training process.
from neural_network import NeuralNetwork
model = NeuralNetwork(neurons=[64, 120, 1])
In this example, we have a four-layer neural network containing auto-defined input neurons, first hidden layer with 64 neurons, second hidden layer with 120 neurons, and one output neuron.
Training the Model
To train the model, you need to provide the input data and the corresponding target (or label) data.
X = np.array([[0, 0], [0, 1], [1, 0], [1, 1]])
y = np.array([[0], [1], [1], [0]])
model.fit(X, y, epochs=1000, learning_rate=0.1, optimizer='adam')
When training the model without setting the activation functions or/and the loss functions, the framework will automatically do the job for you. It will initialize the parameters and the functions according to the type of model (regression or classification) and its architecture.
Making predictions
Once the model has been trained, you can use it to make predictions by simple call predict method.
predictions = model.predict(X)
Beyond the Framework
Apart from the neural network framework, the package also provides:
Activation functions
| Sigmoid function | sigmoid() |
| Hyperbolic tangent function | tanh() |
| Rectified linear unit | relu() |
| Leaky Rectified linear unit | leaky_relu() |
| Softmax function | softmax() |
| Gaussian error linear unit | gelu() |
All above functions have 2 parameters:
x: The input values. Even though some functions can accept numeric primitive data type, it is advised to use NumPy array.derivative: A boolean value indicating whether the function computes the derivative on the inputx. Default is False.
Loss functions
| Logistic loss function | log_loss() |
| Cross-entropy loss function | cross_entropy_loss() |
| Quadratic loss function | quadratic_loss() |
All above functions have 3 parameters:
y_pred: Predicted labels. It must be a 2D NumPy array and have the same size asy_true.y_true: True labels. It must be a 2D NumPy array and have the same size asy_pred.derivative: A boolean value indicating whether the function computes the derivative. Default is False.
2D Decision Boundary
This utility function is used for illustrative purpose. It takes a trained binary classification model, a 2D NumPy input data with 2 attributes, and the corresponding binary label data as input. The function then will plot a 2D decision boundary based on the prediction of the model.
The input model is not necessarily an instance of NeuralNetwork, but it must have predict
method that accepts a 2D NumPy array as input.
plot_decision_boundary(model, train_x, train_y)
License
This project has MIT License, as found in the LICENSE file.
Metadata
Release files for neural-network 0.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| neural_network-0.1.2.tar.gz | 12.9 kB | Without provenance | Details for neural_network-0.1.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| neural_network-0.1.2-py3-none-any.whl | Python 3 | none | any | Details for neural_network-0.1.2-py3-none-any.whl |
Total release size: 24.0 kB
Release files / neural_network-0.1.2.tar.gz
| Download URL | neural_network-0.1.2.tar.gz |
|---|---|
| Size | 12.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5b15953ab0107004c3240b5ed6efae1adf6f0c134c6528ec8566ca1a07597a49
|
|
BLAKE2b-256 checksum How to use checksums |
caff5d0b223ff64be09cb530f76d7c64c9f313613a28eaef58e8a8c64ee6f3fd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.7
|
Release files / neural_network-0.1.2-py3-none-any.whl
| Download URL | neural_network-0.1.2-py3-none-any.whl |
|---|---|
| Size | 11.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c20d31fb660f269f8da42897f30dfa38b71e43bdd8b65afa13e78f7231eae5fd
|
|
BLAKE2b-256 checksum How to use checksums |
cac33518033ed780905ecf63b3e33b5fbd4a4cd5750113a1dd6bfb73d49d1472
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.7
|
Security for neural-network 0.1.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.