Please Verify my code for Accuracy Calculation

def computeAccuracy(X,Y,X_test,Y_test) :
m = X_test.shape[0]
# print(m)
accurate = 0
for i in range(m) :
pred = knn(X_train,Y_train,X_test[i])
if(int(pred) == Y_test[i]) :
accurate += 1

print('Accuracy = ',(accurate*100)/m)

computeAccuracy(X_train,Y_train,X_test,Y_test)

Sir , It’s keep running for more than 15 mins and doesn’t giving Output . Please check if it is right or not?

hey @shubhambarnwal02 ,
looking at this now , looks good and okay , i don’t know why are you getting this error.
Can you share your complete code so that i can check it .

Sir , this doesn’t give any error . It just keep running for a very long time . What should I do ?

it might be getting stuck in loop , i need to check .
share your code.

Sir , here is the link …

I run this code in jupyter notebook . Please check .

hey @shubhambarnwal02 ,
Your code is correct the reason is due to high dimensionality , it is currently taking around 5 seconds to compute accuracy for a single sample.
Hence, in total as there are 420 samples , so in total 2100 seconds ~ 33 mins.
Hence it is taking time.

Try using PCA to lower the dimensions of the data, it will work fine ad fast then.

1 Like

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.