Professional Documents
Culture Documents
Logistic Regression
Logistic Regression
❑ Problem formulation
❑ Summary
Logistic Regression
▪ Logistic regression is a simple classification algorithm for
learning to predict a discrete variable such as predicting whether
a person is
▪ This is not the case in logistic regression, because the error will
always be less than 1 since both model output and label is ≤1
Logistic Regression-Objective Function
▪ In logistic regression, we use cross entropy as the objective
function
Intuition behind the Objective Function
Intuition behind the Objective Function
Intuition behind the Objective Function
Multi-Class Classification
Multi-Class Logistic Regression
Multi-Class Logistic Regression
Multi-Class Logistic Regression
Multi-Class Logistic Regression
Logistic Regression in Python With scikit-learn
▪ General steps to prepare classification models:
1. Import packages, functions, and classes
2. Get data to work with and, if appropriate, transform
it
3. Create a classification model and train (or fit) it with
your existing data
4. Evaluate your model to see if its performance is
satisfactory
A sufficiently good model that we define can be used to
make further predictions related to new, unseen data.
Logistic Regression in Python With scikit-learn
Step 1: Import Packages, Functions, and Classes
import matplotlib.pyplot as plt
import numpy as np
From sklearn.linear_model import LogisticRegression
from sklearn.metrics import classification_report,
confusion_matrix
Step 2: Get Data
x = np.arange(10).reshape(-1, 1)
y = np.array([0, 0, 0, 0, 1, 1, 1, 1, 1, 1])
Note: .reshape() with the arguments -1 to get as many rows as
needed and 1 to get one column
Logistic Regression in Python With scikit-learn
Step 3: Create a Model and Train It
model = LogisticRegression(solver='liblinear', random_state=0)
model.classes_
array([0, 1])
model.intercept_
array([-1.04608067])
model.coef_
array([[0.51491375]])
Logistic Regression in Python With scikit-learn
Step 4: Evaluate the Model
model.predict_proba(x)
❑ Problem formulation
1. https://realpython.com/logistic-regression-python/
Thanks