Convert my model predicted array to categorical using a condition
I've built a MLP neural network -&gt; Trained -&gt; Saved -&gt; loaded -&gt; now I'm testing my loaded model.
I've used y_pred=loaded_model(Variable(featuresTest)) to predict using pytorch then converted my tensor to array y_pred_arr and here's my result:
array([[-1.1663326 ,  0.369073  ],
       [-1.4255922 ,  0.23584184],
       [-2.045612  ,  1.4165274 ],
       ...,
       [ 4.327711  , -4.1331964 ],
       [-1.255816  ,  0.65834284],
       [ 6.642277  , -7.4430957 ]], dtype=float32)

My true labels array y_test which I'm trying to compare to are categorical
array([[0., 1.],
       [0., 1.],
       [0., 1.],
       ...,
       [1., 0.],
       [0., 1.],
       [1., 0.]], dtype=float32)

now I'm trying to use sklearn.metrics -&gt;classification report however as my predicted array is obviously continuous I'm trying to convert it to a categorical which uses a condition converting the highest positive number in each of the array to a 1 for instance:
my first set in the predicted array is  [-1.4255922 ,  0.23584184], &lt;- this would be converted to [ 0 , 1] as 0.2358 is the highest positive class in the prediction.
I've tried to use:
from keras.utils.np_utils import to_categorical
labels123 = to_categorical(y_pred_arr, dtype = &quot;int64&quot;)

however, got this error:
IndexError: index -75 is out of bounds for axis 1 with size 74

Could I please get some assistance with this. Any help would be appreciated

Try this instead.
from keras.utils.np_utils import to_categorical
labels123 = to_categorical(np.argmax(y_pred_arr, 1), dtype = &quot;int64&quot;)

