From 53b6fe15c93aa4a69d1f42710c320efa7ab5ae26 Mon Sep 17 00:00:00 2001 From: Stephen Lee <245885195@qq.com> Date: Fri, 22 Sep 2017 10:30:19 +0800 Subject: [PATCH] improve --- Neural_Network/neuralnetwork_bp3.py | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/Neural_Network/neuralnetwork_bp3.py b/Neural_Network/neuralnetwork_bp3.py index 5c4f879ed..23ce7395e 100644 --- a/Neural_Network/neuralnetwork_bp3.py +++ b/Neural_Network/neuralnetwork_bp3.py @@ -9,7 +9,7 @@ BP neural network with three layers import numpy as np import matplotlib.pyplot as plt -class Bpnw(): +class Bpnn(): def __init__(self,n_layer1,n_layer2,n_layer3,rate_w=0.3,rate_t=0.3): ''' @@ -38,7 +38,7 @@ class Bpnw(): def do_round(self,x): return round(x, 3) - def trian(self,patterns,data_train, data_teach, n_repeat, error_accuracy,draw_e = bool): + def trian(self,patterns,data_train, data_teach, n_repeat, error_accuracy, draw_e=False): ''' :param patterns: the number of patterns :param data_train: training data x; numpy.ndarray @@ -127,8 +127,26 @@ class Bpnw(): def main(): - #I will fish the mian function later - pass + #example data + data_x = [[1,2,3,4], + [5,6,7,8], + [2,2,3,4], + [7,7,8,8]] + data_y = [[1,0,0,0], + [0,1,0,0], + [0,0,1,0], + [0,0,0,1]] + + test_x = [[1,2,3,4], + [3,2,3,4]] + + #building network model + model = Bpnn(4,10,4) + #training the model + model.trian(patterns=4,data_train=data_x,data_teach=data_y, + n_repeat=100,error_accuracy=0.1,draw_e=True) + #predicting data + model.predict(test_x) if __name__ == '__main__': main()