How to build a machine learning model in Python from scratch