10.11.2016 Views

Learning Data Mining with Python

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Classifying Objects in Images Using Deep <strong>Learning</strong><br />

We then import some requirements, which we will explain as we use them:<br />

from lasagne import updates<br />

from nolearn.lasagne import NeuralNet<br />

from lasagne.nonlinearities import sigmoid, softmax<br />

Next we define the neural network, which is represented as a scikit-learn-compatible<br />

estimator:<br />

net1 = NeuralNet(layers=layers,<br />

Note that we haven't closed off the parenthesis—this is deliberate. At this point, we<br />

enter the parameters for the neural network, starting <strong>with</strong> the size of each layer:<br />

input_shape=X.shape,<br />

hidden_num_units=100,<br />

output_num_units=26,<br />

The parameters here match the layers. In other words, the input_shape parameter<br />

first finds the layer in our layers that has given the name input, working much the<br />

same way as setting parameters in pipelines.<br />

Next, we define the nonlinearities. Again, we will use sigmoid for the hidden layer<br />

and softmax for the output layer:<br />

hidden_nonlinearity=sigmoid,<br />

output_nonlinearity=softmax,<br />

Next, we will use bias nodes, which are nodes that are always turned on in the<br />

hidden layer. Bias nodes are important to train a network, as they allow for<br />

the activations of neurons to train more specifically to their problems. As an<br />

oversimplified example, if our prediction is always off by 4, we can add a bias of -4<br />

to remove this bias. Our bias nodes allow for this, and the training of the weights<br />

dictates the amount of bias that is used.<br />

The biases are given as a set of weights, meaning that it needs to be the same size as<br />

the layer the bias is attaching to:<br />

hidden_b=np.zeros((100,), dtype=np.float32),<br />

[ 256 ]

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!