By: Alicia Wei
I majored in applied mathematics in college, and while in school there was not a strong demand to write readable or flexible code. In classes like Graph Theory and Optimization, we used R and Matlab. Our steamroll coding style worked fine at the time – as long as the code didn’t break, we got an A.
After graduation I got curious about machine learning and explored writing scripts in Python. When I asked my friend Sergei, a machine learning engineer at Pinterest, to review my code, that was when I learned the basics of modular programming and other best practices.
A few tips:
- To avoid issues associated with hard-coding, every step of the modeling process (i.e. loading, processing, visualizing, exploring, modeling, evaluating, deploying) must be contained within a separate function with placeholder parameters and return values.
- There is a main() function that calls the functions listed above, allowing for greater flexibility and readability.
- Documentation: Create a docstring to generate a webpage to be used as an interactive help system or as metadata.
Tip #1: Modular Programming
Tip #2: Docstring