Implemented the Neural Network training