Professional Documents
Culture Documents
Regression
Logistic Regression
Los
Patient Status t
After Five Years
Survived
Patient Los
Status t
After Five
Years
Survived
Number of Positive
Nodes
𝑦𝛽 𝑥 = 𝛽0 + 𝛽1𝑥 + ε
Linear Regression for
Classification?
Patient Lost:
Status 1.0
After Five 0.5
Years
Survived: 0.0
Number of Positive
Nodes
𝑦𝛽 𝑥 = 𝛽0 + 𝛽1𝑥 + ε
Linear Regression for
Classification?
Patient Lost:
Status 1.0
After Five 0.5
Years
Survived: 0.0
Patient Lost:
Status 1.0
After Five 0.5
Years 0 0 0 0
Survived: 0.0
values (0, 1)
The predicted probabilities can be greater than 1 or less
than 0
Probabilistic Approach
Learn P(Y|X) directly
Cumulative probability distribution
Using a sigmoid function
Probabilistic Approach
P(Y|X) using sigmoid function
1
🞑𝑃 𝑌=1 X =
1+exp(-𝐗𝐛)
exp -𝐗𝐛
🞑𝑃 𝑌=0𝑋 =1−𝑃 𝑌=1 𝑋 =
1+exp -𝐗𝐛
1
=
1 + exp(𝐗𝐛)
What is this
Function?
1.0
1
0.8
𝑦 =
0.6 1+𝑒 −𝑥
0.4
0.2
0.0
-10 -5 0 5 10
Understanding the sigmoid
Logistic Regression Model
1
𝑃 𝑌=1 𝑋 =
1 + exp(-𝐗𝐛)
1
𝑃 𝑌=0𝑋 =
1 + exp(𝐗𝐛)
𝑃 𝑌=1𝑋
log = 𝐗𝐛
𝑃 𝑌=0𝑋
Logistic
Regression
Patient Lost:
Status 1.0
After Five 0.5
Years
Survived: 0.0
Number of Positive
Nodes
1
𝑦� 𝑥 =
� 1+𝑒 −(𝛽 0 + 𝛽 1 𝑥 + ε )
Relationship of Logistic to Linear
Regression
1
Logistic 𝑃 𝑥 =
1 + 𝑒 −(𝛽 0+ 𝛽 1 𝑥 + 𝗌 )
Functio
n
Relationship of Logistic to Linear
Regression
1
Logistic 𝑃 𝑥
= 1 + 𝑒 −(𝛽 0+ 𝛽 1 𝑥 + 𝗌 )
Functio
n 𝑒 (𝛽 0 + 𝛽 1 𝑥 )
1+𝑒 (𝛽 0 + 𝛽 1 𝑥 )
𝑃 𝑥 =
Relationship of Logistic to Linear
Regression
Logistic 𝑃 𝑥 = 𝑒 (𝛽 0 + 𝛽 1 𝑥 )
1+𝑒 (𝛽 0 + 𝛽 1 𝑥 )
Functio
n
Relationship of Logistic to Linear
Regression
Logistic 𝑃 𝑥 = 𝑒 (𝛽 0 + 𝛽 1 𝑥 )
1+𝑒 (𝛽 0 + 𝛽 1 𝑥 )
Functio
n
Odd 𝑃 𝑥
s 𝛽 0+ 𝛽 1 𝑥
1−𝑃 𝑥 =𝑒
Ratio
Relationship of Logistic to Linear
Regression
Logistic 𝑃 𝑥 = 𝑒 (𝛽 0 + 𝛽 1 𝑥 )
1+𝑒 (𝛽 0 + 𝛽 1 𝑥 )
Functio
n
Log 𝑃 𝑥
Odd 𝑙𝑜𝑔 = 𝛽0 + 𝛽1𝑥
1−𝑃 𝑥
s
Relationship of Logistic to Linear
Regression
Logistic 𝑃 𝑥 = 𝑒 (𝛽 0 + 𝛽 1 𝑥 )
1+𝑒 (𝛽 0 + 𝛽 1 𝑥 )
Functio
n
Log 𝑃 𝑥
Odd 𝑙𝑜𝑔 = 𝛽0 + 𝛽1𝑥
1−𝑃 𝑥
s
Maximum Likelihood Estimation (MLE)
Likelihood function: probability of the observed data as a
function of the unknown parameters
To estimate unknown parameters that maximize the
likelihood of getting the data we observed in a
probabilistic model.
Likelihood Function
Logistic regression predicts probabilities rather than classes:
Stochastic approach
🞑 Fit the model using likelihood
🞑 Maximum Likelihood Estimation
Likelihood Function
Negative log-
likelihood
🞑 Minimization problem
🞑 Solveby Gradient
Descent
20
Logistic Regression: The
Syntax
Import the class containing the classification method
from sklearn.linear_model import LogisticRegression
0.2
Wors
e
0.2 0.4 0.6 0.8 1.0
False Positive Rate (1 –
Specificity)
(Sensitivity)
0.4 AUC
0.5
0.2
Actual
Class
TP2 Most multi-class error
2 metrics are similar to
binary versions—
TP3 just expand elements
Actual
Class as a sum
3
Classification Error Metrics: The
Syntax
Import the desired error function
from sklearn.metrics import accuracy_score