Can you please provide the code for finding out the accuracy of test set in the MNIST handwritten project using KNN
Code for finding out accuracy of test set
tejas simply count the number of cases in which , test case value is equal to the generated output using simple loop.Then divide it by total number of test cases.
accuracy = (total number of cases in which test value equals generated value)/(total number of test cases)
This is the code that I wrote ,
correctCase = 0
for i in X_test:
pred = knn(X_train,Y_train,X_test[i])
if pred == Y_test[i]:
correctCase += 1
accuracy = (correctCase) / (len(X_test))
print(accuracy)
But its giving a value error that says “the truth value of an array with more than one element is ambiguous. use a.any() or a.all() ”
Please help
hi tejas;
I appreciate ur efforts.
Plz use loop in different way to get results
for i in range(X_test.shape[0]):
if pred == Y_test[i]
because for i in X_test is iterating over X_test iterating as an object and not a number that we are using to iterate over index of Y_test.
that’s why erorr occuring