CS231n icon indicating copy to clipboard operation
CS231n copied to clipboard

Incorrect Cross-validation for knn.

Open nghiattran opened this issue 8 years ago • 1 comments

In knn.ipynb file, you have:

y_cross_validation_pred = classifier_k.predict_labels(X_train_folds[n], k)

This is incorrect because predict_labels takes in a distance matrix but you pass in a raw test matrix. So, you need to have an additional step as:

dists = classifier.compute_distances_no_loops(X_train_folds[n])
y_cross_validation_pred = classifier_k.predict_labels(dists, k)

Or you can use predict function in k_nearest_neighbor which technically does the same thing:

y_cross_validation_pred = classifier_k.predict(dists, k)

nghiattran avatar Jan 16 '17 04:01 nghiattran

@nghiattran Yes but if you use the predict function then you would pass in the raw test matrix, not the distance matrix

gebrial avatar Jan 07 '18 00:01 gebrial