I get an error with my code like this
for n, df_process in enumerate(all_df):
#Normalisasi data dengan metode Standard Scaler
scaler=StandardScaler()
scaler.fit(df_process)
scaled_data=scaler.transform(df_process)
#Menentukan jumlah komponen dalam PCA
if n == 0:
pca=PCA(n_components=total_faktor_positif, svd_solver='full')
else:
pca=PCA(n_components=total_faktor_negatif, svd_solver='full')
#Fitting PCA dari data yang sudah normalisasi
pca.fit(scaled_data)
#Dicari PCA dari data yang sudah normalisasi
x_pca=pca.transform(scaled_data)
factor = []
for pc in x_pca:
factor.append(np.argmax(pc))
all_factor.append(factor)
print (all_factor)
all_pca.append(x_pca)
how can I fix them? please help:( because today is my essay
The n_components
of PCA
must be lower than min(n_samples, n_features)
.
In this case, min(n_samples, n_features)=2
, so n_components
only accept value between [0,2], but you give it 4
.
You can try with: n_components=2