I follow the script in the knn.ipynb and implemented the function "compute_distances_two_loops"
like
for i in range(num_test):
for j in range(num_train):
#####################################################################
# TODO: #
# Compute the l2 distance between the ith test point and the jth #
# training point, and store the result in dists[i, j]. You should #
# not use a loop over dimension, nor use np.linalg.norm(). #
#####################################################################
# *****START OF YOUR CODE (DO NOT DELETE/MODIFY THIS LINE)*****
dists[i,j] = np.sqrt(np.sum((X[i]-self.X_train[j])**2))
# *****END OF YOUR CODE (DO NOT DELETE/MODIFY THIS LINE)*****
return dists
and I also referenced most of the solutions on the website and alter my answer like:
dists[i,j] = np.sqrt(np.sum(np.square(X[i]-self.X_train[j])))
# or
dists[i,j] = np.sqrt(np.sum(np.power(X[i]-self.X_train[j], 2)))
# ..... some answer like these
All their pages said that they got the accuracy of 0.274 (so do the script write )
while I can only get 0.114
I follow the script in the knn.ipynb and implemented the function "compute_distances_two_loops" like
and I also referenced most of the solutions on the website and alter my answer like:
All their pages said that they got the accuracy of 0.274 (so do the script write )
while I can only get 0.114
Someone please could help me T^T