<commit_before>---
layout: post
author: csiu
date: 2017-03-24
title: "Day28: Modularization (Python)"
categories: update
tags:
  - 100daysofcode
  - machine-learning
excerpt: Modularizing yesterday's script.
---

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.

- *[Structuring, Testing, and Maintaining Python Programs](http://intermediate-and-advanced-software-carpentry.readthedocs.io/en/latest/structuring-python.html#packages) (Titus Brown, 2007)*

### 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](https://www.kaggle.com/c/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

<script src="https://gist.github.com/csiu/84bb4703b9a0eb2c5be898bfd8464176.js"></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.

 - *[Convolutional Neural Networks (CNNs / ConvNets)](http://cs231n.github.io/convolutional-networks/) (karpathy, 2016)*<commit_msg>Remove spacing<commit_after>---
layout: post
author: csiu
date: 2017-03-24
title: "Day28: Modularization (Python)"
categories: update
tags:
  - 100daysofcode
  - machine-learning
excerpt: Modularizing yesterday's script.
---

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.

- *[Structuring, Testing, and Maintaining Python Programs](http://intermediate-and-advanced-software-carpentry.readthedocs.io/en/latest/structuring-python.html#packages) (Titus Brown, 2007)*

### 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](https://www.kaggle.com/c/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

<script src="https://gist.github.com/csiu/84bb4703b9a0eb2c5be898bfd8464176.js"></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.

 - *[Convolutional Neural Networks (CNNs/ConvNets)](http://cs231n.github.io/convolutional-networks/) (karpathy, 2016)*
{'fraction_non_alphanumeric': 0.08853450646136926, 'fraction_numerical': 0.028045092108880947, 'mean_word_length': 4.7746031746031745, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 4, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2970129', 'n_tokens_mistral': 1144, 'n_tokens_neox': 1023, 'n_words': 449}