Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python: DeprecationWarning: elementwise == comparison failed; this will raise an error in the future

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?

like image 386
Arslan Avatar asked Jun 15 '17 18:06

Arslan


1 Answers

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
like image 150
hpaulj Avatar answered Sep 16 '22 11:09

hpaulj