Created
June 19, 2018 15:59
-
-
Save lironsade/c6c8522cd6582f165b678433c5493d55 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 hinge_loss(w, data, labels): | |
size = labels.shape | |
return np.mean(np.maximum(np.zeros(size), np.ones(size) - labels * np.dot(data, w))) | |
def hinge_loss_deriv(w, data, labels): | |
deriv_sum = np.zeros() | |
for x_i, y_i in zip(data, labels): | |
if (y_i * np.dot(x_i, w)): | |
deriv_sum -= y_i * x_i | |
return deriv_sum / labels.shape | |
def GD(data, label, iters, eta): | |
out = np.zeros((labels.shape, t)) | |
for i in range(iters - 1): | |
out[i + 1] = out[i] - eta * hinge_loss_deriv(w, data, labels) | |
return out | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment