I wrote my code for this project in VS Code using Python 3.8.5 and found that the same code copied into Codecademy produced a different result. I am curious as to why the output would be different.
Namely, the output to question 9 is what changes.
In VS Code, the output to the following print function is [-2. 2. 0.].
print(classifier.decision_function([[0, 0], [1, 1], [0.5, 0.5]]))
In Codecademy, the output is [-4. 1. -1.5].
Why are these outputs different for the same code?
Here is my code.
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]
classifier = Perceptron(max_iter = 40)
classifier.fit(data, labels)
print(classifier.score(data, labels))
print(classifier.decision_function([[0, 0], [1, 1], [0.5, 0.5]]))
x_values = np.linspace(0,1,100)
y_values = np.linspace(0,1,100)
point_grid = list(product(x_values, y_values))
distances = classifier.decision_function(point_grid)
abs_distances = [abs(point) for point in distances]
distances_matrix = np.reshape(abs_distances, (100, 100))
heatmap = plt.pcolormesh(x_values, y_values, distances_matrix)
plt.colorbar(heatmap)
plt.scatter([point[0] for point in data], [point[1] for point in data], c= labels)
plt.show()