I'm trying to calculate the accuracy of a model I created using the function below:
def accuracy(y_true, y_pred):
accuracy = np.mean(y_pred == y_true)
return accuracy
Sometimes it displays the accuracy correctly and sometimes its incorrect. Can someone explain how can i fix the function to have it display the same accuracy as sklearn accuracy_score. Here's an example of the results I am getting from my method.
y_true
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0]
y_pred
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0]
KNN classification accuracy: 0.0
KNN classification accuracy sklearn: 0.9428571428571428