'How to modify the Face Recognition using eigenfaces and SVMs based on scikit-learn example?

I am trying to adapt the existing example for face recognition using scikit-learn and considering my own dataset (https://scikit-learn.org/stable/auto_examples/applications/plot_face_recognition.html#sphx-glr-auto-examples-applications-plot-face-recognition-py). I can create a model in the same way they did but the problem occurs when I try to test it based on the image from my own folder. Every time, it was a wrong prediction. I added this extra part for that purpose:

from skimage.transform import resize
from skimage.color import rgb2gray
import numpy
test_img = plt.imread('path_with_Bush_picture')
test_img = resize(test_img, (62, 47))
test_img = rgb2gray(test_img)
plt.imshow(test_img, cmap=plt.cm.gray)
plt.show()
testImageVector = numpy.array(test_img).flatten()
test.append(testImageVector)
test = scaler.transform(test)
test_imag_PCA = pca.transform(test[0].reshape(1, -1))
img_predict = clf.predict(test_imag_PCA)
print(target_names[img_predict[0]])
print(img_predict)

In this case, I want to predict if Bush is on the image, but it gives me another famous person as result. And that is for every case, same prediction doesn't matter who on the read photo is. Does anybody know how to handle this issue? Any kind of help will be useful. Thanks in advance!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source