Training and evaluating the model

After parameter tuning, we can now run the model for maximum performance. In order to do so, we will make a few important changes to the model options. Ahead of making the changes, let's have a more in-depth review of the model options:

Now, that we have covered the options included in our model using the mlp() function, we will make adjustments to improve accuracy. In order to improve accuracy, we will increase the number of rounds while simultaneously dropping the learning rate. We will keep the other values constant and use the node count that led to the best performance from our loop earlier. You can set the model for better performance using what we learned when parameter tuning using the following code:

model <- mx.mlp(data.matrix(train), train_target, hidden_node=90, out_node=2, out_activation="softmax",num.round=200, array.batch.size=32, learning.rate=0.005, momentum=0.8,eval.metric=mx.metric.accuracy)

preds = predict(model, data.matrix(test))

pred.label = max.col(t(preds))-1

acc = sum(pred.label == test_target)/length(test_target)

acc

After running this code, you will see a printout in your console with the accuracy score after running the model with the adjustments to the parameters. Your console output will look like this:

We can see that our accuracy has improved from our adjustments. Before, when we were testing parameters, the best accuracy we could achieve was 84.28%, and we can see that we now have an accuracy score of 85.01%.

After preparing our data so that it is in the proper format to model with MXNet, and then parameter tuning to find the best values for our model, we then made adjustments to further improve performance using what we learned earlier. All of these steps together describe a complete cycle of manipulating and transforming data, optimizing parameters, and then running our final model. We saw how to use MXNet, which offers a convenience function for simple MLPs and also offers the functionality to build MLPs with additional hidden layers using the activation, output, and feedforward functions.