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, and split the read dataset into training and testing subsets. We then call the fitLogisticRegression(...)
method to estimate the model (the classification_logistic.py
file):
@hlp.timeit def fitLogisticRegression(data): ''&apos...