4 Reasons Why Your Machine Learning Code is Probably Bad
Your current ML workflow probably chains together several functions executed linearly. Instead of linearly chaining functions, data science code is better written as a set of tasks with dependencies between them. That is your data science workflow should be a DAG.
By Norman Niemer, Chief Data Scientist
Your current workflow probably chains several functions together like in the example below. While quick, it likely has many problems:
- it doesn't scale well as you add complexity
- you have to manually keep track of which functions were run with which parameter
- you have to manually keep track of where data is saved
- it's difficult for others to read
What to do about it?
Instead of linearly chaining functions, data science code is better written as a set of tasks with dependencies between them. That is your data science workflow should be a DAG.
So instead of writing a function that does:
You are better of writing tasks that you can chain together as a DAG:
The benefits of doings this are:
- All tasks follow the same pattern no matter how complex your workflow gets
- You have a scalable input
requires()and processing function
- You can quickly load and save data without having to hardcode filenames
- If the input task is not complete it will automatically run
- If input data or parameters change, the function will automatically rerun
An example machine learning DAG
Below is a stylized example of a machine learning flow which is expressed as a DAG. In the end you just need to run TaskTrain() and it will automatically know which dependencies to run. For a full example see https://github.com/d6t/d6tflow/blob/master/docs/example-ml.md
Writing machine learning code as a linear series of functions likely creates many workflow problems. Because of the complex dependencies between different ML tasks it is better to write them as a DAG. https://github.com/d6t/d6tflow makes this very easy. Alternatively you can use luigi and airflow but they are more optimized for ETL than data science.
Bio: Norman Niemer is the Chief Data Scientist at a large asset manager where he delivers data-driven investment insights. He holds a MS Financial Engineering from Columbia University and a BS in Banking and Finance from Cass Business School (London).
Original. Reposted with permission.
- The Machine Learning Project Checklist
- Data Science Project Flow for Startups
- End To End Guide For Machine Learning Projects
Top Stories Past 30 Days