Fully Connected Neural Networks
Fully Conected Neural Networks module.
Contains Dense and Dropout layers along with ReLU and SoftMax activation functions.
This module is based on the syntax that Tensorflow/Keras uses.
from NN import Model
from NN.layers import Dense, Dropout
from NN.activations import ReLU, SoftMax
from NN.loss import CatCrossEntr
from NN.optimizers import SGDOptimizer
# the X and y datasets
X = a_dataset
y = another_dataset
# create loss and optimizer objects
loss = CatCrossEntr()
optimizer = SGDOptimizer(lr=0.1, decay=1E-3, momentum=0.6)
# create Model object
model = Model()
model.add(Dense(2, 32))
model.add(ReLU())
model.add(Dropout(rate=0.2))
model.add(Dense(32, 3))
model.add(SoftMax())
# finalize the model
model.finalize(loss=loss, optimizer=optimizer)
# train the model
model.fit(X, y, epochs=300,validation_data=None, verbose=2)
The Model object
- class mapyl.NN.Model[source]
Model for sequential, fully connected layers
- Returns:
self: The Model class
- finalize(*, loss, optimizer)[source]
Finalizes the model, adds loss and optimizer
- parameters:
loss (Loss): Loss object
optimizer (Optimizer): Optimizer object
- Returns:
self: the finalized Model object
- fit(X, y, epochs, validation_data=None, verbose=0)[source]
trains and validades the Model instance
- Parameters:
X (ndarray): ndarray of shape (num_samples, num_features) of the input
y (ndarray): ndarray of shape (num_samples, num_features) of the input
epochs (int): The number of epochs
validation_data (tuple): Validation data of shape (X ndarray , y ndarray). Defaults to None.
verbose (int): The verbose, can be 0, 1 and 2. Defaults to 0.
- Returns:
self: The fitted instance