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 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.