Closed
Description
IncrementalPCA.partial_fit
raises the following error when the number of samples is smaller than n_components
:
File "___/sklearn/decomposition/incremental_pca.py", line 218, in partial_fit
(self.components_.shape[0], self.n_components_))
ValueError: Number of input features has changed from 10 to 20 between calls to partial_fit!
Try setting n_components to a fixed value.
This error can be generated via the following snippet as long as n_samples < n_components
:
import numpy as np
from sklearn.decomposition import IncrementalPCA
n_samples, n_features = 10, 50
ipca = IncrementalPCA(n_components=20)
for i in range(5):
ipca.partial_fit(np.random.rand(n_samples, n_features))
The error message is not informative because the number of input features is constant (i.e., 50)
and n_components
is fixed anyways.
Also, I don't see any fundamental reason why this shouldn't work. In regular PCA, number of components after transformation can be larger than the number of samples.
Is this a limitation of the incremental PCA algorithm or the implementation?