Logistic regression classifier
This approach can be chosen where the output can take only two values, 0 or 1, pass/fail, win/lose, alive/dead, or healthy/sick, and so on. In cases where the dependent variable has more than two outcome categories, it may be analyzed using multinomial logistic regression.
How to do it...
- After installing the essential packages, let's construct some training labels:
import numpy as np from sklearn import linear_model import matplotlib.pyplot as plt a = np.array([[-1, -1], [-2, -1], [-3, -2], [1, 1], [2, 1], [3, 2]]) b = np.array([1, 1, 1, 2, 2, 2])
- Initiate the classifier:
classification = linear_model.LogisticRegression(solver='liblinear', C=100) classification.fit(a, b)
- Sketch datapoints and margins:
def plot_classification(classification, a , b): a_min, a_max = min(a[:, 0]) - 1.0, max(a[:, 0]) + 1.0 b_min, b_max = min(a[:, 1]) - 1.0, max(a[:, 1]) + 1.0 step_size = 0.01 a_values, b_values = np.meshgrid(np.arange(a_min, a_max, step_size), np.arange(b_min, b_max...