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)
‘’’