The Collatz conjecture

Posted on Sun 02 June 2019 in Math • Tagged with python, math

The Collatz conjecture is a conjecture in mathematics that concerns a sequence defined as follows: start with any positive integer n. Then each term is obtained from the previous term as follows: if the previous term is even, the next term is one half the previous term. If the previous term is odd, the next term is 3 times the previous term plus 1. The conjecture is that no matter what value of n, the sequence will always reach 1.

Collatz

Continue reading

MNIST pixel attacks with Pytorch

Posted on Sat 01 June 2019 in Machine Learning • Tagged with python, pytorch, cnn, torchvision, mnist, skl

It’s easy to build a CNN that does well on MNIST digit classification. How easy is it to break it, to distort the images and cause the model to misclassify?

MNIST attack accuracy

Continue reading

Solving CIFAR-10 with Pytorch and SKL

Posted on Tue 14 May 2019 in Machine Learning • Tagged with python, pytorch, cnn, torchvision, cifar, skl

CIFAR-10 is a classic image recognition problem, consisting of 60,000 32x32 pixel RGB images (50,000 for training and 10,000 for testing) in 10 categories: plane, car, bird, cat, deer, dog, frog, horse, ship, truck. Convolutional Neural Networks (CNN) do really well on CIFAR-10, achieving 99%+ accuracy. The Pytorch distribution includes an example CNN for solving CIFAR-10, at 45% accuracy. I will use that and merge it with a Tensorflow example implementation to achieve 75%. We use torchvision to avoid downloading and data wrangling the datasets. Like in the MNIST example, I use Scikit-Learn to calculate goodness metrics and plots.

CIFAR examples

Continue reading

Solving MNIST with Pytorch and SKL

Posted on Thu 02 May 2019 in Machine Learning • Tagged with python, pytorch, cnn, torchvision, mnist, skl

MNIST is a classic image recognition problem, specifically digit recognition. It contains 70,000 28x28 pixel grayscale images of hand-written, labeled images, 60,000 for training and 10,000 for testing. Convolutional Neural Networks (CNN) do really well on MNIST, achieving 99%+ accuracy. The Pytorch distribution includes a 4-layer CNN for solving MNIST. Here I will unpack and go through this example. We use torchvision to avoid downloading and data wrangling the datasets. Finally, instead of calculating performance metrics of the model by hand, I will extract results in a format so we can use SciKit-Learn's rich library of metrics.

MNIST example digits

Continue reading

SVM with Pytorch

Posted on Tue 16 April 2019 in Machine Learning • Tagged with pytorch, svm, iris

I use the standard Iris dataset for supervised learning with a Support Vector Machine model using Pytorch's autograd.

SVM

Continue reading

Hacker News Embeddings with PyTorch

Posted on Tue 12 March 2019 in Machine Learning • Tagged with pytorch embedding

A PyTorch model is trained on public Hacker News data, embedding posts and comments into a high-dimensional vector space, using the mean squared error (MSE) of dot products as the loss function. The resulting model is reasonably good at finding similar posts and recommending posts for users.

Vector space

Continue reading

rxe: literate and composable regular expressions

Posted on Sat 02 March 2019 in Python • Tagged with python

rxe is a thin wrapper around Python's re module. The various rxe functions are wrappers around corresponding re patterns. For example, rxe.digit().one_or_more('a').whitespace() corresponds to \da+\s. Because rxe uses parentheses but wants to avoid unnamed groups, the internal (equivalent) representation is actually \d(?:a)+\s. This pattern can always be retrieved with get_pattern().

rxe example code

Continue reading

PyTorch Basics: Solving the Ax=b matrix equation with gradient descent

Posted on Fri 08 February 2019 in Machine Learning • Tagged with pytorch

I will show how to solve the standard A x = b matrix equation with PyTorch. This is a good toy problem to show some guts of the framework without involving neural networks.

PyTorch computational graph

Continue reading

Automating a Call Center with Machine Learning

Posted on Sun 27 January 2019 in Machine Learning • Tagged with fetchr, machine-learning, call-center

Over a period of 6 months, we rolled out a Machine Learning model to predict a customer’s delivery (latitude, longitude). During the recent holiday peak, this ML model handled most of Fetchr’s order scheduling.

Share of ML scheduled versus Call center scheduled deliveries

Continue reading

5 things that happened in Data Science in 2018

Posted on Wed 09 January 2019 in Data • Tagged with data, openai, waymo, deepmind, tesla, reinforce

2018 was a hot year for Data Science and AI. Here we picked out 5 highlights, which in our opinion shaped the field in the past year.

Deepmind playing CTF

Continue reading

Warehouse locations with k-means

Posted on Wed 26 September 2018 in Data • Tagged with data, data-science, metrics

Sometimes, the seven gods of data science, Pascal, Gauss, Bayes, Poisson, Markov, Shannon and Fisher, all wake up in a good mood, and things just work out. Recently we had such an occurence at Fetchr, when the Operational Excellence team posed the following question: if we could pick our Saudi warehouse locations, where would be put them? What is the ideal number of warehouses, and, what does ideal even mean? Also, what should our “delivery radius” be?

Continue reading

Growth Accounting and Backtraced Growth Accounting

Posted on Sun 16 September 2018 in Data • Tagged with data, data-science, metrics, growth-accounting

Previously I wrote two articles about data infra and data engineering at Fetchr. This time I want to move up the stack and talk about a simple piece of metrics engineering that proved to be very impactful: Growth Accounting and Backtraced Growth Accounting.

Backtraced Growth Accounting

Continue reading

Fetchr Data Science Infra at 1 year

Posted on Tue 14 August 2018 in Data • Tagged with data, etl, workflow, airflow, fetchr, model, ml

A description of our Analytics+ML cluster running on AWS, using Presto, Airflow and Superset.

Fetchr Data Science Infra

Continue reading

What not to spend time on

Posted on Mon 23 July 2018 in General • Tagged with warren, buffett, self, help, physics, haskell

Warren Buffett says deciding what not to spend time on is just as important as deciding what to spend time on.

Warren Buffett

Continue reading

Beat the averages

Posted on Sat 07 July 2018 in Data • Tagged with data, statistics

When working with averages, we have to be careful. There are pitfalls lurking to pollute our statistics and results reported.

Probability distribution

Continue reading

Building the Fetchr Data Science Infra on AWS with Presto and Airflow

Posted on Wed 14 March 2018 in Data • Tagged with data, etl, workflow, airflow, fetchr

We used Hive/Presto on AWS together with Airflow to rapidly build out the Data Science Infrastructure at Fetchr in less than 6 months.

Warehouse DAG

Continue reading

Don’t build cockpits, become a coach

Posted on Wed 09 November 2016 in Data • Tagged with data, science, product, analytics

I used to think that a good analogy for using data is the instrumentation of a cockpit in an airliner. Lots of instruments, and if they fail, the pilot can’t fly the plane and bad things happen. There’s no autopilot for companies. The problem with this analogy is that planes aren’t built in mid-air. Product teams and companies constantly need to build and ship new products.

A big complicated cockpit

Continue reading

Beautiful A/B testing

Posted on Sun 05 June 2016 in ab-testing • Tagged with ab-testing, strata

I gave this talk at the O’Reilly Strata Conference London in 2016 June, mostly based on what I learned at Prezi from 2012-2016.

14. slide

Continue reading

Hack, HHVM and avoiding the Second-system effect

Posted on Sat 14 May 2016 in Books • Tagged with books, programming, hhvm, brooks

I read this book on my first vacation after I started working at Facebook and thus became a semi-regular Hack/HHVM user. I highly recommend reading (parts of) it. But not to learn Hack/PHP, which is irrelevant to most people. Instead, it’s to learn about how Facebook improved it’s www codebase and performance without rewriting the old PHP code in one big effort, and thus avoided the famous Second-system effect.

Hack book

Continue reading

Einstein's amazing theory

Posted on Tue 16 February 2016 in Physics • Tagged with physics, einstein, relativity

This post is about the amazing success of Einstein's general theory of relativity. The theory predicts, among other things the accelerating Universe, black holes, gravitational lensing and gravitational waves. The real shocker is to remember that Einstein didn't invent general relativity to explain these. He didn’t know about these, they didn't exist at that time!

Continue reading

Heisengames and the importance of patience in business

Posted on Mon 08 February 2016 in Business • Tagged with heisengames, business

Most bets businesses take, be it hiring, features, products or strategy don't work out. Still, many businesses are successful despite setbacks. A negative attitude---even when the analysis of the situation is in fact correct---may be missing the bigger picture.

Continue reading

Cloud9: Cloud coding that actually works

Posted on Sun 07 February 2016 in Coding • Tagged with coding, ide, c9

For the past 2 months I've been using Cloud9 for writing code in the cloud, and I can wholeheartedly recommend it: it just works for me. It's basically Docker plus an IDE: you get a Docker container running Ubuntu that you can access over a web IDE.

Continue reading

Luigi vs Airflow vs Pinball

Posted on Sat 06 February 2016 in Data • Tagged with data, etl, workflow, luigi, airflow, pinball

A spreadsheet comparing the three opensource workflow tools for ETL.

Comparison

Continue reading

Pinball review

Posted on Sat 06 February 2016 in Data • Tagged with data, etl, workflow, pinball

Pinball is an ETL tool written by Pinterest. Like Airflow, it supports defining tasks and dependencies as Python code, executing and scheduling them, and distributing tasks across worker nodes. It supports calendar scheduling (hourly/daily jobs, also visualized on the web dashboard). Unfortunately, I found Pinball has very little documentation, very few recent commits in the Github repo and few meaningful answers to Github issues by maintainers, while it's architecture is complicated and undocumented.

Continue reading

How to make a blog like this

Posted on Thu 07 January 2016 in Meta • Tagged with blog, pelican

Make a simple blog with Github Pages and Pelican.

Continue reading

Airflow review

Posted on Wed 06 January 2016 in Data • Tagged with data, etl, workflow, airflow

Airflow is a workflow scheduler written by Airbnb. It supports defining tasks and dependencies as Python code, executing and scheduling them, and distributing tasks across worker nodes. It supports calendar scheduling (hourly/daily jobs, also visualized on the web dashboard), so it can be used as a starting point for traditional ETL. It has a nice web dashboard for seeing current and past task state, querying the history and making changes to metadata such as connection strings.

Airflow

Continue reading

Systems thinking and system traps

Posted on Wed 06 January 2016 in Books • Tagged with systems, books

Thinking in Systems, written by the late Donella Meadows, is a book about how to think about systems, how to control systems and how systems change and control themselves. A system can be anything from a heating furnace to a social system. The gem of the book is the part about system traps. System traps are ways a system can go wrong; examples are drift to low performance, seeking the wrong goals, shifting the burden, etc.

Thinking in systems

Continue reading

Luigi review

Posted on Sun 20 December 2015 in Data • Tagged with data, etl, workflow, luigi

I review Luigi, an execution framework for writing data pipes in Python code. It supports task-task dependencies, it has a simple central scheduler with an HTTP API and an extensive library of helpers for building data pipes for Hadoop, AWS, Mysql etc. It was written by Spotify for internal use and open sourced in 2012. A number of companies use it, such as Foursquare, Stripe, Asana.

Continue reading

Cargo Cult Data

Posted on Mon 26 January 2015 in Data • Tagged with data

Cargo cult data is when you're collecting and looking at data when making decisions, but you're only following the forms and outside appearances of scientific investigation and missing the essentials, so it doesn't work.

Continue reading