I am currently working on an image recognition project with machine learning.
- The train set has 1600 images with size 300x300, so 90000 features per image.
- To speed up training, I apply PCA with
n_components = 50
- The test set has 450 images and I can test the model in this test set successfully.
Now, I want to predict a single image that is captured by webcam. The question is that should I apply PCA to that image?
- If I don't apply PCA, I get
ValueError: X.shape[1] = 90000 should be equal to 50, the number of features at training time
- If I apply PCA, I get
ValueError: n_components=50 must be between 0 and min(n_samples, n_features)=1 with svd_solver='full'
I use Python 3, scikit-learn 0.20.3, this is how I apply PCA:
from sklearn.decomposition import PCA
pca = PCA(50)
pca.fit_transform(features)