pyNNRW
pyNNRW: A Python library for NNRW (neural network with random weights).
Basic functions:
- Implements 2 fundamental NNRW flavors, i.e., ELM and RVFL.
- Performance comparison with main machine learning models, e.g., SVM, decision tree, MLP.
- NNRW-based ensembles (in progress).
Publication
Spectroscopic Profiling-based Geographic Herb Identification by Neural Network with Random Weights [J]. Spectrochimica Acta Part A: Molecular and Biomolecular Spectroscopy, 2022, doi: 10.1016/j.saa.2022.121348
Installation
pip install pyNNRW
How to use
Download the sample dataset from the /data folder.
There are two data files: 1. 7044X_RAMAN.csv 2. 7143X_UV.csv.
The two files are the Raman and UV (ultra-violet) spectroscopic profiling data of herb samples from 4 different regions.
Use the following sample code to use the package:
<1> Use low-level classes, e.g., ELM, RVFL. The following code trains and tests an ELM model.
# ===============================
# Import library
# ===============================
# import the library
from pyNNRW import elm, rvfl
# ===============================
# Load dataset
# ===============================
df = pd.read_csv('7044X_RAMAN.csv')
X = np.array(df.iloc[:,1:])
y = np.array(df.iloc[:,0]) # 1st col is the label
n_classes = len(set(y))
x_train, x_test, t_train, t_test = train_test_split(X, y, test_size=0.2)
t_train = to_categorical(t_train, n_classes).astype(np.float32)
t_test = to_categorical(t_test, n_classes).astype(np.float32)
# print(x_train.shape, x_test.shape, t_train.shape, t_test.shape)
# ===============================
# set ELM parameters
# ===============================
n_hidden_nodes = L #x_train.shape[1]
loss = 'mean_squared_error' # 'mean_absolute_error'
activation = 'sigmoid' # 'identity'
# ===============================
# Instantiate ELM
# ===============================
model = elm.ELM( # or rvfl.RVFL
n_input_nodes = x_train.shape[1],
n_hidden_nodes = n_hidden_nodes,
n_output_nodes = n_classes,
loss = loss,
activation=activation,
name='elm'
)
# ===============================
# Training
# ===============================
train_loss, train_acc, train_precision, train_recall = model.evaluate(x_train, t_train, metrics=['loss', 'accuracy', 'precision', 'recall'])
# ===============================
# Validation
# ===============================
val_loss, val_acc, val_precision, val_recall = model.evaluate(x_test, t_test, metrics=['loss', 'accuracy', 'precision', 'recall'])
<2> You may also use high-level APIs, as follows.
from pyNNRW import nnrw
# train and test an ELM model
train_acc, val_acc, t = nnrw.ELMClf(X, y, L = 20, verbose = False) # L is hidden layer nodes
# train and test a RVFL model
train_acc, val_acc, t = nnrw.RVFLClf(X, y, L = 20, verbose = False) # L is hidden layer nodes
# Conduct a performance test for ELM at varied L hyper-parameters (1~60). Each iteration is averaged on 20 rounds.
train_accs, val_accs, ts = nnrw.PerformenceTests(ELMClf, X, y, Ls = list(range(1, 60)), N = 20)
New function in v0.2.0
We added Kernel-NNRW, which provides a series of kernels combined with NNRW.
Metadata
Release files for pyNNRW 0.3.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| pyNNRW-0.3.5.tar.gz | 30.1 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pyNNRW-0.3.5-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 63.0 kB
Release files / pyNNRW-0.3.5.tar.gz
| Download URL | pyNNRW-0.3.5.tar.gz |
|---|---|
| Size | 30.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5ed56817b747cd7106ea10f342faf97bbfb8eabd69c3aa74b5791deee34cf9e8
|
|
BLAKE2b-256 checksum How to use checksums |
e96872cd8535d75d69b150a153495e9e9ab608c08e70e4d96009c39d23b57754
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.9.12
|
Release files / pyNNRW-0.3.5-py3-none-any.whl
| Download URL | pyNNRW-0.3.5-py3-none-any.whl |
|---|---|
| Size | 32.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ab0b52c17d44486eb5a1cc338d9bef3922161b0b50d95255af4cbfd999e65ae7
|
|
BLAKE2b-256 checksum How to use checksums |
6bf92e77be271b0a671afafbe3cfe8689a81c03a9c3e940f1f86a78e25ddc941
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.9.12
|