I came across a problem with comparing the predictions of my model with the labels of training set. The arrays I'm using have shapes:
Training set (200000, 28, 28) (200000,)
Validation set (10000, 28, 28) (10000,)
Test set (10000, 28, 28) (10000,)
However, when checking the accuracy with the function:
def accuracy(predictions, labels):
return (100.0 * np.sum(np.argmax(predictions, 1) == np.argmax(labels, 1))
/ predictions.shape[0])
It's giving me:
C:\Users\Arslan\Anaconda3\lib\site-packages\ipykernel_launcher.py:5: DeprecationWarning: elementwise == comparison failed; this will raise an error in the future. """
And it gives the accuracy as 0% for all datasets.
I think we cannot compare the arrays using '=='. How could I compare the arrays in the right way instead?
I assume the error occurs in this expression:
np.sum(np.argmax(predictions, 1) == np.argmax(labels, 1))
can you tell us something about the 2 arrays, predictions
, labels
? The usual stuff - dtype, shape, some sample values. Maybe go the extra step and show the np.argmax(...)
for each.
In numpy
you can compare arrays of the same size, but it has become pickier about comparing arrays that don't match in size:
In [522]: np.arange(10)==np.arange(5,15)
Out[522]: array([False, False, False, False, False, False, False, False, False, False], dtype=bool)
In [523]: np.arange(10)==np.arange(5,14)
/usr/local/bin/ipython3:1: DeprecationWarning: elementwise == comparison failed; this will raise an error in the future.
#!/usr/bin/python3
Out[523]: False
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With