Skip to content

Instantly share code, notes, and snippets.

@curiousily
Created March 31, 2019 12:35
Show Gist options
  • Save curiousily/dc9811a42669f58cc3c45073df9eba90 to your computer and use it in GitHub Desktop.
Save curiousily/dc9811a42669f58cc3c45073df9eba90 to your computer and use it in GitHub Desktop.
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