1

I am having issues comparing 2 numPy arrays against each other. I am currently doing a classification task and have classified data into either 1's or 0's. I want to compare the predictions against the actual label.

enter image description here

attached is an image of the two arrays. I cannot seem to find a way .

though not ideal, I have tried the following:

for i in range(len(yTrain)):
    yTrain==yPred

I was hoping that it would return a bunch of true and false values which I could manually tally up but that didn't work.

I would like an output which counts the number of inaccuracies. e.g. out of 200 datapoints, 45 were misclassified or something along those lines

Loai Alnouri
  • 83
  • 1
  • 1
  • 8
  • Does this answer your question? [Comparing two NumPy arrays for equality, element-wise](https://stackoverflow.com/questions/10580676/comparing-two-numpy-arrays-for-equality-element-wise) – Lior Cohen Mar 12 '21 at 23:50
  • Please post small sample arrays as text instead of images. – Mad Physicist Mar 13 '21 at 00:44

1 Answers1

1

If you want the count of where yTrain == yPred, you can use np.count_nonzero:

matches = np.count_nonzero(yTrain == yPred)
mismatches = yTrain.size - matches
Mad Physicist
  • 107,652
  • 25
  • 181
  • 264