-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbasic_equations.py
36 lines (25 loc) · 1.03 KB
/
basic_equations.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
from numpy import log, array, transpose, exp
# simple looking code to see if is easier to remember than math style equations
weights = array([1,2,3])
bias = 5
x = array([1,2,3])
def linear_regression(w, b, x):
return transpose(w) * x + b
def sigmoid(z):
return 1/(1+exp(-z))
def logistic_regression(w, b, x)
return sigmoid(linear_regression(w, b, x))
def predict(x):
# y_hat is probability y == 1 given x?
# y_hat is predicted value of y given x?
y_hat = probability(y, x)
def squared_error(predicted_output, correct_output):
return 0.5 * pow((predicted_output-correct_output), 2)
def logistic_loss(predicted_output, correct_output):
return -(correct_output * log(predicted_output) + (1-correct_output) * log(1 - predicted_output))
def cost(predicted_outputs, correct_outputs):
total_loss = 0
number_of_items = len(predicted_outputs)
for index in range(0, number_of_items):
total_loss += logistic_loss(predicted_outputs[index], correct_outputs[index])
return total_loss / number_of_items