first pass at implementing the algorithm in a VERY roughly scikit-learn paradigm. Untested