Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- num = len(X_train) # Get the length of our training data
- no_errors = 0 # Keep track of the number of errors
- distance = np.zeros(num) # Create an array the length of X_trains, filled with zeros
- for j in range(1697, 1797):
- X_test = digits.data[j] # Test values in the range [1697, 1797)
- for i in range(num):
- distance[i] = dist(X_train[i], X_test) # Compute distance from X_train[i] to X_test
- min_index = np.argmin(distance) # Get the index of the minimum distance
- if Y_train[min_index] != digits.target[j]: # If the actual label is not the same as the nearest neighbor, add a count to the number of errors
- no_errors += 1
- print(no_errors)
- 37
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement