4

I want to reduce the dimension of matrix of size (5,3844) using pca dimensionality reduction.I got this error n_components=1000 must be between 0 and min(n_samples, n_features)=2 with svd_solver='full'.

I am trying for more than 5 weeks to find how I can do it.

Any help would be appreciated.

coeffs = wavedec(y, 'sym5', level=5)
cA5,cD5,cD4,cD3,cD2,cD1=coeffs
result = []
    common_x = np.linspace(0,3844, len(cD1))
    for c in [cD5,cD4,cD3,cD2,cD1]:
        x = np.linspace(0, 3844, len(c))
        f = interp1d(x, c)
        result.append(f(common_x)) #(5,3844)
    pca = PCA(n_components=1000)
    pca.fit(result)
    data_pca = pca.transform(result)
    print("original shape:   ", result.shape) ##(5,3844)
    print("transformed shape:", data_pca.shape) 

Eda
  • 565
  • 1
  • 7
  • 18
  • You are doing it correct. You are reducing 3844 features to 2 using PCA – mujjiga Jun 16 '20 at 20:50
  • 1
    @mujjiga but 2 is a few features. I want number of components to be 1000. when I use `n_components=1000` I got this error `n_components=1000 must be between 0 and min(n_samples, n_features)=2 with svd_solver='full'` – Eda Jun 16 '20 at 21:02
  • see https://stats.stackexchange.com/questions/28909/pca-when-the-dimensionality-is-greater-than-the-number-of-samples. the problem is that you are trying to reduce the number of dimensions to 1000, but the actual dimensionality of the problem is 5 (because you have only 5 samples) – itamar kanter Jul 07 '21 at 11:49

0 Answers0