Deep Learning



backpropagation gradients 

SGD  (stochastic gradient descent ) training procedure is as follows:

Regularization

1.       L1 norm /  lasso regression : λf(θ) = ||θ||1 is the sum of all the model parameters

2.      L2 norm:  λf(θ) = ||θ||2 is the sum of squares of all the model parameters


There are six main steps in building a model using Keras: 


Define the model

nn_model = Sequential()

nn_model.add(Dense(35, input_dim=784, activation='relu'))

In case we want to use dropout in the particular layer, we add a Dropout as follows:

nn_model.add(Dropout(0.3))

The argument '0.3' is the percentage of neurons that dropout in a particular iteration.

We add another dense hidden layer with 21 neurons and the 'relu' activation function.

nn_model.add(Dense(21, activation='relu'))

The last layer for our problem is a softmax layer with 10 classes defined as follows:

nn_model.add(Dense(10, activation='softmax'))

Let's consolidate the above code:

nn_model = Sequential()

nn_model.add(Dense(35, input_dim=784, activation='relu'))

nn_model.add(Dropout(0.3))

nn_model.add(Dense(21, activation='relu'))

nn_model.add(Dense(10, activation='softmax'))

 


Compile Model

nn_model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy'])

 


Fit Model

nn_model.fit(train_set_x, train_set_y, epochs=10, batch_size=10)

 

Evaluate Model

In this step we see the accuracy scores that we finally achieved using the following command:

scores_train = nn_model.evaluate(train_set_x, train_set_y)

print("\n%s: %.2f%%" % (nn_model.metrics_names[1], scores_train[1]*100))

To get the score on the test data, we can write the following:

scores_test = nn_model.evaluate(test_set_x, test_set_y)

print("\n%s: %.2f%%" % (nn_model.metrics_names[1], scores_test[1]*100))

Please note that we only changed the dataset from train to test.

 

Predict

The predictions can be performed using '.predict()' in the following way:

predictions = nn_model.predict(test_set_x)




 


Convolutional Neural Networks 


Applications of CNNs


the layers in the network should do something like this:


VGGNet