title: Calculate the accuracy of a machine learning model without sklearn
body: <p>I'm trying to calculate the accuracy of a model I created using the function below:</p>
  <pre><code>def accuracy(y_true, y_pred):
      accuracy = np.mean(y_pred == y_true)
      return accuracy
  </code></pre>
  <p>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.</p>
  <pre><code>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
  </code></pre>