In [2]:
#
# NeuralNetwork Example
#
# @author becxer
# @email becxer87@gmail.com
#
import numpy as np
from pytrain.NeuralNetwork import FNN
In [3]:
# Simple dataset
train_mat = [[0.12, 0.25],\
[3.24, 4.33],\
[0.14, 0.45],\
[7.30, 4.23],]
train_label = [[0,1],\
[1,0],\
[0,1],\
[1,0]]
test_a = [0.10,0.33]
test_b = [4.0,4.5]
In [4]:
# Train model
hidden_layer = [3]
fnn = FNN(train_mat, train_label, hidden_layer)
fnn.fit(lr = 0.01, epoch = 2000, err_th = 0.001, batch_size = 4)
In [5]:
# Test model
res_a = np.rint(fnn.predict(test_a))
res_b = np.rint(fnn.predict(test_b))
print("X %s => Y %s" % (test_a, res_a))
print("X %s => Y %s" % (test_b, res_b))