Training and testing the logistic regression model

Now, let's create a function that trains a logistic regression model. This function needs to perform the following:

  1. Accept our FICO score data as an independent variable.
  2. Add an intercept to our model.
  3. Initialize and optimize the coefficients (or weights) of the logistic regression model.
  4. Return the optimized weights which define our trained model.

To optimize the coefficient/weights, we will use a technique called stochastic gradient descent. This technique will be covered in greater detail in the Appendix, Algorithms/Techniques Related to Machine Learning. For now, suffice it to say that we are trying to make predictions with some non-optimized weights, calculating an error for those ...

Get Machine Learning With Go now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.