Advertisement
lessientelrunya

test2

Jun 28th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.67 KB | None | 0 0
  1. num = len(X_train) # Get the length of our training data
  2. no_errors = 0 # Keep track of the number of errors
  3. distance = np.zeros(num) # Create an array the length of X_trains, filled with zeros
  4. for j in range(1697, 1797):
  5.     X_test = digits.data[j] # Test values in the range [1697, 1797)
  6.     for i in range(num):
  7.         distance[i] = dist(X_train[i], X_test) # Compute distance from X_train[i] to X_test
  8.     min_index = np.argmin(distance) # Get the index of the minimum distance
  9.     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
  10.         no_errors += 1
  11. print(no_errors)
  12. 37
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement