COMP-377Week6 v1.1
COMP-377Week6 v1.1
Logistic Regression
and Support Vector
Machines
Lesson 6 Objectives
𝑒 𝛽0 + 𝛽1 ∙𝑥
𝑝Ƹ = + 𝛽1 ∙𝑥 +1, where 𝑝Ƹ (p-hat) denotes an estimated
𝑒 𝛽0
probability.
12 7/18/2021 AI for Software Developers
Logistic Regression
❑ Recall:
➢ In linear regression we tried to predict the value of y(i) for
the i‘th example x(i) using a linear function:
𝑦 = ℎ𝛽 (𝑥)=𝛽 ⊤ 𝑥
❑ In logistic regression we use sigmoid function to “squash” the
value of 𝛽 ⊤ 𝑥 into the range [0,1] so that we may interpret
ℎ𝛽 (𝑥)as a probability.
❑ The goal is to search for a value of 𝛽 so that the probability
P(y=1|x)=ℎ𝛽 (𝑥) is large when x belongs to the “1” class and
small when x belongs to the “0” class (so that P(y=0|x) is
large).
import numpy as np
import pandas as pd
from sklearn import datasets
from sklearn import linear_model
import seaborn as sns
%matplotlib inline
import matplotlib.pyplot as plt
sns.set(style='whitegrid', context='notebook')
df = pd.read_csv("data/CHD.csv", header=0)
plt.figure() # Create a new figure
plt.axis ([0,70,-0.2,1.2])
plt.title('Original data')
plt.scatter(df['age'],df['chd']) #Plot a scatter draw of the random datapoints
print(__doc__)
digits = datasets.load_digits()
_, axes = plt.subplots(nrows=1, ncols=4, figsize=(10, 3))
for ax, image, label in zip(axes, digits.images, digits.target):
ax.set_axis_off()
ax.imshow(image, cmap=plt.cm.gray_r, interpolation='nearest')
ax.set_title('Training: %i' % label)
❑ Textbook
❑ Andriy Burkov, The Hundred-Page Machine Learning Book, 2019
❑ https://scikit-learn.org/stable/modules/linear_model.html#logistic-
regression
❑ Vishal Maini, Samer Sabri, Machine Learning for Humans, 2017
❑ http://ufldl.stanford.edu/tutorial/supervised/LinearRegression/
❑ http://ufldl.stanford.edu/tutorial/supervised/LogisticRegression/
❑ https://scikit-
learn.org/stable/auto_examples/classification/plot_digits_classificati
on.html
❑ https://www.learnpython.org/