logistic regression

This commit is contained in:
Ritchie
2017-09-10 13:54:17 +02:00
parent f351e89421
commit 5b68b7ec43
3 changed files with 428 additions and 0 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 107 KiB

File diff suppressed because one or more lines are too long

View 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))