Perceptron Project

When I type in the following code from the project, i get an output for the decision_function() of [-2, 2, 0]. This would mean the boundary line runs through 2 of my points and is also inconsistent with the code walkthrough. What did I type incorrectly?

from sklearn.linear_model import Perceptron
import matplotlib.pyplot as plt
import numpy as np
from itertools import product

data = [[0,0], [0,1], [1,0], [1,1]]
labels = [0, 0, 0, 1]

plt.scatter([point[0] for point in data], [point[1] for point in data], c = labels)

classifier = Perceptron(max_iter = 40), labels)

print(classifier.score(data, labels))
print(classifier.decision_function([[0, 0], [1, 1], [0.5, 0.5]]))

What is your intended goal?

Just working through the project where it’s supposed to help visualize where the decision boundary line would be. Only problem is that the way I’ve coded it, the decision boundary runs through 2 of the 3 “negative” decision points

I’m pretty confident it’s the same answer as in this thread:


Perfect! That’s it. Thank you!

1 Like