Using linear methods for classification – logistic regression

Linear models can actually be used for classification tasks. This involves fitting a linear model to the probability of a certain class, and then using a function to create a threshold at which we specify the outcome of one of the classes.

Getting ready

The function used here is typically the logistic function (surprise!). It's a pretty simple function:

Getting ready

Visually, it looks like the following:

Getting ready

Let's use the make_classification method, create a dataset, and get to classifying:

>>> from sklearn.datasets ...

Get scikit-learn : Machine Learning Simplified now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.