I want to my code to return multiple(5) predictions from my trained knn model. I've tried using predict_proba() but it just returns the probabilities and not the names Here is my code:
import cv2
import numpy as np
import pickle
import npwriter
m=open('finalmodel.train','rb')
model = pickle.load(m)
cap = cv2.VideoCapture(0)
classifier = cv2.CascadeClassifier(cv2.data.haarcascades + "haarcascade_frontalface_default.xml")
X_test = []
while True:
ret, frame = cap.read()
cv2.imshow('Press c to capture your face', frame)
if cv2.waitKey(1) & 0xFF == ord('c'):
cv2.destroyAllWindows()
cap.release()
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
faces = classifier.detectMultiScale(gray, 1.5, 5)
for face in faces:
x, y, w, h = face
im_face = gray[y:y + h, x:x + w]
im_face = cv2.resize(im_face, (100, 100))
X_test.append(im_face.reshape(-1))
if len(faces) > 0:
response = model.predict(np.array(X_test))
print(response)
break