Using logistic regression as a universal classifier

Logistic regression is probably the second most (after linear regression) popular regression model. However, it can be easily adapted to solve a classification problem.

Getting ready

To run this recipe, you will need pandas and StatsModels; if you use the Anaconda distribution of Python, both of the modules are included in the distribution. We import two parts of StatsModels:

import statsmodels.api as sm
import statsmodels.genmod.families.links as fm

The first one allows us to select our models and the other one to specify the link function. No other prerequisites are required.

How to do it…

Following a similar pattern to our previous recipe, we import all the necessary modules first, read in the data, ...

Get Practical Data Analysis Cookbook 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.