logistic regression
This commit is contained in:
BIN
logistic_regression/img/log_likelihood.png
Normal file
BIN
logistic_regression/img/log_likelihood.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 107 KiB |
382
logistic_regression/logistic_regression.ipynb
Normal file
382
logistic_regression/logistic_regression.ipynb
Normal file
File diff suppressed because one or more lines are too long
46
vanilla_logistic_regression.py
Normal file
46
vanilla_logistic_regression.py
Normal file
@@ -0,0 +1,46 @@
|
||||
import numpy as np
|
||||
|
||||
"""
|
||||
# Logistic Regression
|
||||
|
||||
w^T · x = w0 + w1x1 + w2x2 + w3x3
|
||||
|
||||
P(A|x) = σ(w^Tx)
|
||||
|
||||
# Given data:
|
||||
|
||||
D = ((x1, y1), ..., (xn, yn))
|
||||
x ∈ R
|
||||
y ∈ {0, 1}
|
||||
|
||||
|
||||
# Pro's:
|
||||
|
||||
- interpretable
|
||||
- small # params (d + 1)
|
||||
- computationally efficient
|
||||
- extensible to multi-class
|
||||
|
||||
# Cons
|
||||
|
||||
- performance as good as other models
|
||||
|
||||
# Maximum Likelihood Estimation MLE
|
||||
|
||||
labels y
|
||||
input x
|
||||
|
||||
likelihood lw = P(y[i]| x[i], w) * P(y[j] | x[j], w) ... P(y[n] | x[n],w)
|
||||
|
||||
in product notation
|
||||
|
||||
lw =
|
||||
"""
|
||||
|
||||
|
||||
def sigmoid(z):
|
||||
"""
|
||||
:param z: w^Tx (scalar)
|
||||
:return: σ(w^Tx) (scalar)
|
||||
"""
|
||||
return 1 / (1 + np.exp(-z))
|
||||
Reference in New Issue
Block a user