Day28: Modularization (Python)

Posted by csiu on March 24, 2017 | with: 100daysofcode, Machine Learning

Yesterday was a great start. I laid out my foundation and now I want to dedicate some time in refactoring and modularizing the code so that it can be reused and easily modified.

Implemented changes

  1. Built 2 new class types: (1) BasicMLP to define, train, and get the outputs of a basic multilayer perceptron; and (2) ToyData to load the Kaggle Digit Recognizer data and write out the prediction in the competition’s submission format.

  2. Defined the parser as a function (getargs) so that it can later be imported and reused. Adding additional arguments to the parser allows me to e.g. specify different number of nodes in the hidden layer, the number of epochs (training cycles), and the learning rate, which would increase the number neural networks from 1 (as of yesterday’s script) to many.

  3. Added if __name__ == '__main__': to allow the import of functions without the running of code at import.

Updated script

Future work

I defined a fully-connected neural network, but my features are spatial related. In the future work, I will modify the code to enable the specification of convolutional neural networks.