pca = PCA(n_components = 5) reduced_data = pca.fit_transform(standardized_df) #data_var = pca.explained_variance_ratio_ principal_df=pd.DataFrame(reduced_data) principal_df.head() code example
Example: pca python
import numpy as np
from sklearn.decomposition import PCA
pca = PCA(n_components = 3) # Choose number of components
pca.fit(X) # fit on X_train if train/test split applied
print(pca.explained_variance_ratio_)