Code from Chapter 2 of Machine Learning: An Algorithmic Perspective