From the course: Training Neural Networks in Python
Unlock the full course today
Join today to access over 24,600 courses taught by industry experts.
Solution: Finish the multilayer perceptron class - Python Tutorial
From the course: Training Neural Networks in Python
Solution: Finish the multilayer perceptron class
(bright upbeat music) - [Presenter] Here's my solution. For the set-weights method starting at line 54, I'm implementing W-init as a list of lists of lists. That's three dimensions and that's because I'm specifying the layer, the neuron, and the input associated to each weight. However, W-init will have one less entry in the first dimension because I'm not specifying anything for the input layer as it has no neurons. So I implemented two nested loops starting at line 57. The outer loop iterates I through the layers in the network, and the inner loop iterates J through the neurons in each layer. Now, inside the inner loop, I'm using the set-weights method for each neuron. Notice that since W-init doesn't have anything for the input layer, I am indexing the network array at I-plus-one. Now let's look at the run method starting at line 68. So here, the first thing I do is turning X into a NumPy array. Then, I copy X…