Baking with sympy

Problem: a recipe calls for 250ml double cream (48% fat) and 100ml whole milk (3.5% fat). I only have double cream (48% fat) and semi-skimmed milk (1.5% fat).

How much do I adjust the double cream by to get the same quantity liquid and fat content?

It’s a simple simultaneous equation, so solving it with Sympy is overkill, but developers do overkill best, right?

So:

>>> linsolve([Eq(x + y, 350), Eq(x*.48 + y*.015, 250*.48 + 100*.035)], (x, y))

ie. volume must be 350ml, fat must equal the original recipe.

[Read More]

Deploying a scikit-learn classifier to production

Scikit-learn is a great python library for all sorts of machine learning algorithms, and really well documented for the model development side of things. But once you have a trained classifier and are ready to run it in production, how do you go about doing this?

There’s a few managed services that will do it for you, but for my situation these weren’t a good fit. We just wanted to deploy the model onto a modest sized Digital Ocean instance, as a REST API that can be externally queried.

[Read More]