manning icon indicating copy to clipboard operation
manning copied to clipboard

Perceptron notebook doesn't follow book

Open hitsvilleusa opened this issue 2 years ago • 0 comments

In the notebook, you have:

def perceptron_trick(weights, bias, features, label, learning_rate = 0.01):
    pred = prediction(weights, bias, features)
    for i in range(len(weights)):
        weights[i] += (label-pred)*features[i]*learning_rate
        bias += (label-pred)*learning_rate
    return weights, bias

but in the book, the bias is not done for each iteration of the loop:

def perceptron_trick(weights, bias, features, label, learning_rate = 0.01):
    pred = prediction(weights, bias, features)
    for i in range(len(weights)):
        weights[i] += (label-pred)*features[i]*learning_rate
    bias += (label-pred)*learning_rate
    return weights, bias

Unfortunately, this leads to different numbers than those that are published in the book

hitsvilleusa avatar Oct 10 '22 20:10 hitsvilleusa