Implementing logistic regression with Python