Logistic regression

Introduction to Predictive Analytics in Python

Nele Verbiest, Ph.D

Data Scientist @PythonPredictions

Logistic regression: intuition

Introduction to Predictive Analytics in Python

Logistic regression: the logit function

  • Output of $a*age + b$ is a real number
  • We want to predict a 0 or a 1
  • Logit function transforms $a*age + b$ to a probability

Introduction to Predictive Analytics in Python

Logistic regression in Python

from sklearn import linear_model

logreg = linear_model.LogisticRegression()
X = basetable[["age"]]
y = basetable[["target"]]
logreg.fit(X,y)
print(logreg.coef_)
[[ 0.02449202]]
print(logreg.intercept_)
[-4.3299131]
Introduction to Predictive Analytics in Python

Multivariate logistic regression

Univariate: $ax + b$

Multivariate: $a_1x_1 + a_2x_2 + ... + a_nx_n + b$

X = basetable[["age","max_gift","income_low"]]

y = basetable[["target"]]
logreg.fit(X,y)
print(logreg.coef_)
[[ 0.0243308   0.03906065 -0.76793773]]
print(logreg.intercept_)
[-8.80643545]
Introduction to Predictive Analytics in Python

Let's practice!

Introduction to Predictive Analytics in Python

Preparing Video For Download...