Advertisement
Guest User

Untitled

a guest
Jan 20th, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.56 KB | None | 0 0
  1. classifier = KNearestNeighbor()
  2. for i, k in enumerate(k_choices):
  3.     k_accuracy = np.zeros(num_folds)
  4.     for j in range(num_folds):
  5.         X_train =
  6.         classifier.train(cross_X_train, cross_y_train)
  7.         dists = classifier.compute_distances_no_loops(X_train_folds[j])
  8.         cross_y_test_pred = classifier.predict_labels(dists, k)
  9.         cross_num_correct = np.sum(cross_y_test_pred == y_train_folds[j])
  10.         cross_accuracy = float(num_correct) / (X_train_folds[j].shape[0])
  11.         k_accuracy[j] = cross_accuracy
  12.     k_to_accuracies[k] = k_accuracy
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement