Created
March 31, 2019 12:35
-
-
Save curiousily/dc9811a42669f58cc3c45073df9eba90 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def add_intercept(X): | |
intercept = np.ones((X.shape[0], 1)) | |
return np.concatenate((intercept, X), axis=1) | |
def predict(X, W): | |
X = add_intercept(X) | |
return sigmoid(np.dot(X, W)) | |
def fit(X, y, n_iter=100000, lr=0.01): | |
X = add_intercept(X) | |
W = np.zeros(X.shape[1]) | |
for i in range(n_iter): | |
z = np.dot(X, W) | |
h = sigmoid(z) | |
gradient = np.dot(X.T, (h - y)) / y.size | |
W -= lr * gradient | |
return W |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment