Machine learning pattern recognition Python