cs231n / cs231n.github.io

Public facing notes page
MIT License
10.06k stars 4.06k forks source link

Why i got the accuracy of 0.114 in Assignment 1 KNN exercise? #301

Closed ShenHaoyuan closed 2 months ago

ShenHaoyuan commented 2 months ago

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

Someone please could help me T^T

ShenHaoyuan commented 2 months ago

That's my fault, sorry. I havnt implement the function predict_labels().