Frank Hinek (4) [Avatar] Offline
#1
There is an error in the code on page 56. The weight is never actually updated, so the loop iterates 20 times and terminates without ever producing a super prediction. Additionally, the prediction isn't actually printed out. An undefined variable "prediction" is printed instead of "pred".

The "knob_weight" reference in the loop should be replaced with "weight" and the reference to the "prediction" variable should be replaced with "pred".

Change:
weight = 0.5
goal_pred = 0.8
input = 0.5

for iteration in range(20):
    pred = input * weight
    error = (pred - goal_pred) ** 2
    direction_and_amount = (pred - goal_pred) * input
    knob_weight = weight - direction_and_amount
    
    print("Error:" + str(error) + " Prediction:" + str(prediction))


to

weight = 0.5
goal_pred = 0.8
input = 0.5

for iteration in range(20):
    pred = input * weight
    error = (pred - goal_pred) ** 2
    direction_and_amount = (pred - goal_pred) * input
    weight = weight - direction_and_amount
    
    print("Error:" + str(error) + " Prediction:" + str(pred))