Search code examples
pythonmachine-learningsvm

Getting Name of Images at which SVM mispredicted


I am working on a Binary Classification Model and i want to know the names of the Images that the model mispredicted .How can i do this ?

to_be_moved = random.sample(glob.glob("/content/COVID-19_Radiography_Dataset/COVID/images/*.png"), 1500)

label= 0
for img in tqdm(to_be_moved):
    imgstate= cv2.imread(img,0)
    resizedimage=cv2.resize(imgstate,(220,220))
    fd = hog(resizedimage, orientations=9, pixels_per_cell=(2, 2),cells_per_block=(1,1), visualize=False, multichannel=False)
    data.append([fd,label])


random.shuffle(data)
features= []
labels=[]
for feature , label in data :
  features.append(feature)
  labels.append(label) 

from sklearn.model_selection import train_test_split
from sklearn.svm import SVC
X_train , X_test , y_train , y_test = train_test_split(features,labels, test_size=0.25)
model = SVC(C=1,kernel='linear',gamma ='auto' )
model.fit(X_train , y_train)

Solution

  • You can extend the data tuple to include the fd , pathofimage , and label. And then after the splitting , you can then after train,test,split divide the tuple and by this you will get the path as well as the images it predicted .Remember to set the shuffle to False