Monogram mark of Manish Shivanandhan
Manish Shivanandhan
Full Stack Web, Deep Learning & D3 Visualizations Engineer

Choosing a Python ML workflow

Machine learning workflow · applies to: Python, Scikit, TensorFlow · last updated 2016-05-14

Scikit-learn and TensorFlow answer different questions, and the choice usually follows from the shape of the data.

Where the lighter tool wins

Rows and columns, a few thousand to a few million of them, with meaning attached to each column: this is the case a conventional library is built for. Fitting takes one call, the result is often interpretable, and the whole experiment fits on one machine.

Starting here also produces the baseline that any heavier approach has to beat. Skipping the baseline means never learning whether the heavier approach earned its complexity.

Where the heavier tool wins

Raw signals where the useful features are not columns at all, but relationships across pixels, samples or tokens. Here the point of the framework is that the representation is learned rather than designed, which needs many parameters, much data and hardware that can push them.

The same framework is also the right answer when a custom loss or a custom layer has to be expressed, because building the computation graph directly is exactly what it offers.

A workable order

Establish the dumbest defensible baseline first, then a conventional model on engineered columns, and only then a learned representation. Each stage tells you what the next one has to beat and how much of the remaining error is reducible at all.

Deciding in order

  1. Describe the data: tabular columns with meaning, or a raw signal.
  2. Measure a trivial baseline, such as always predicting the most common class.
  3. Fit a conventional model on engineered columns and compare against that baseline.
  4. Only if the gap justifies it, move to a learned representation.
  5. Compare every stage on the same held-out split, using the same metric.
from sklearn.dummy import DummyClassifier
baseline = DummyClassifier(strategy="most_frequent").fit(train_x, train_y)
print(baseline.score(test_x, test_y))   # anything else must beat this

The baseline is one line and it is not optional

Worth knowingA heavier model that beats the baseline by less than the variation between reruns has not been shown to beat it at all.

Return to Machine learning workflow