Is it possible to display the missclassified Videos From a confusion matrix?

Hi All programmers,

In reference to the caption,

Is it possible?

I am classifying video data, where everything works fine, but when it comes to the CONFUSION MATRIX I am not sure what video is being misclassified and what video that might be.

Now, the confusion matrix works fine, I would like to visualise the misclassifications to further analyse why this scenario is happening

I am trying to display all of the misclassified videos from the confusion matrix operations that were dispensed in the output to see what videos are causing the issue.

what I tried is: GOOGLing and this code below

‘’’
X_train, Xval_test, Y_train, Yval_test = train_test_split(
X, Y, train_size=0.8, test_size=0.2, random_state=1, stratify=Y, shuffle=True)

#Ground truth (correct) target values.
y_valtest_arg = np.argmax(Yval_test, axis=1)

#Estimated targets as returned by a classifier
Y_valpred = np.argmax(model.predict(Xval_test), axis=1)  # model
print('y_valtest_arg Shape is ==>', y_valtest_arg.shape)
print('Y_valpred Shape is ==>', Y_valpred.shape)

‘’‘Intitate Confusion Matrix’’’
# print(‘Model Confusion Matrix Per Test Data Completed===>’)
cm = confusion_matrix(y_valtest_arg, Y_valpred, normalize=None)

print('Display Confusion Matrix ===>', cm)

# conf = confusion_matrix(y_valtest_arg, Y_valpred)


index = filehandle
columns = filehandle
cm_df = pd.DataFrame(cm, columns, index)
cm_df.dtypes
plt.figure(figsize=(6, 6))
plt.yticks(rotation=45, fontsize=5,)
plt.xticks(rotation=45, ha='right', fontsize=5)
sns.heatmap(cm_df, annot=True, xticklabels=True, yticklabels=True)
plt.savefig('model_cmatrixDisp.jpg')

misclassifiedIndexes = np.where(y_valtest_arg!=Y_valpred)[0]

fig, ax = plt.subplots(4, 3,figsize=(15,8))
ax = ax.ravel()
for i, badIndex in enumerate(misclassifiedIndexes):
    ax[i].imshow(np.reshape(Xval_test[badIndex], (8, 8)), cmap=plt.cm.colors)
    ax[i].set_title(f'Predict: {Y_valpred[badIndex]}, 'f'Actual: {Yval_test[badIndex]}', fontsize = 10)
    ax[i].set(frame_on=False)
    ax[i].axis('off')
plt.box(False)
plt.axis('off')

#ERRORS RECEIVED:
Traceback (most recent call last):
File “3dcnn9.py”, line 1175, in
main()
File “3dcnn9.py”, line 919, in main
ax[i].imshow(np.reshape(Xval_test[badIndex], (8, 8)), cmap=plt.cm.colors)
File “<array_function internals>”, line 180, in reshape
File “/Users/mmgp0hotmail.com/opt/anaconda3/envs/DataScience/lib/python3.8/site-packages/numpy/core/fromnumeric.py”, line 298, in reshape
return _wrapfunc(a, ‘reshape’, newshape, order=order)
File “/Users/mmgp0hotmail.com/opt/anaconda3/envs/DataScience/lib/python3.8/site-packages/numpy/core/fromnumeric.py”, line 57, in _wrapfunc
return bound(*args, **kwds)
ValueError: cannot reshape array of size 36864 into shape (8,8)

‘’’

unfortunately none of this is related to opencv

besides that, no, unless all instances of a certain class were misclassified, you cant know which instances (e.g. 5 of 17) were right or wrong from the confusion matrix alone (it holds only “counters” for class ids)

Ok @berak thanx for your swift response, my code above deploy Opencv and not sure if this may have had an impact on the error hence posted here.

The example was taken from this link: python 3.x - Display misclassified digits from confusion matrix - Stack Overflow

This is what I’m following and this is possible here. It would mean a whole lot if this can be done for my processing!

anticipating your response and thanx in advance

definitely not so. but an arbitrary python problem:

now go find out, what sqrt(36864) is, aand you got the solution, i guess …

blindly copypasting from SO wont get you anywhere, just saying.

the square root? I don’t get it!!
can you guide me here a little further and thanx in advance once more

@berak that is 192 but how do I apply this not sure what the direction is here

please start using your own head (and get a maths book, learn about numpy)

@berak wow ok then, if I understood the context of using it in the code then it would have helped!

No worries thanx!