How to do it...

Let's see how to build a logistic regression classifier:

  1. Let's see how to do this in Python. We will use the logistic_regression.py file, provided to you as a reference. Assuming that you imported the necessary packages, let's create some sample data, along with training labels:
import numpy as npfrom sklearn import linear_modelimport matplotlib.pyplot as pltX = np.array([[4, 7], [3.5, 8], [3.1, 6.2], [0.5, 1], [1, 2], [1.2, 1.9], [6, 2], [5.7, 1.5], [5.4, 2.2]])y = np.array([0, 0, 0, 1, 1, 1, 2, 2, 2])

Here, we assume that we have three classes (0, 1, and 2).

  1. Let's initialize the logistic regression classifier:
classifier = linear_model.LogisticRegression(solver='lbfgs', C=100)

There are a number of input parameters that ...

Get Python Machine Learning Cookbook - Second Edition 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.