Skip to content

Instantly share code, notes, and snippets.

@coreyjs
Created October 11, 2020 16:08
Show Gist options
  • Save coreyjs/cca84457c46fd6d41a70ee586ade5b9b to your computer and use it in GitHub Desktop.
Save coreyjs/cca84457c46fd6d41a70ee586ade5b9b to your computer and use it in GitHub Desktop.
Sigmoid, yhat, error forumula and weight updating
def sigmoid(x):
return 1 / (1 + np.exp(-x))
def output_formula(features, weights, bias):
return sigmoid(np.dot(features, weights) + bias)
def error_formula(y, output):
return - y*np.log(output) - (1 - y) * np.log(1-output)
def update_weights(x, y, weights, bias, learnrate):
output = output_formula(x, weights, bias)
d_error = y - output
weights += learnrate * d_error * x
bias += learnrate * d_error
return weights, bias
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment