1import numpy as np
2from sklearn.decomposition import PCA
3
4pca = PCA(n_components = 3) # Choose number of components
5pca.fit(X) # fit on X_train if train/test split applied
6
7print(pca.explained_variance_ratio_)
1from sklearn.decomposition import KernelPCA
2kpca = KernelPCA(n_components = 2, kernel = 'rbf')
3X_train = kpca.fit_transform(X_train)
4X_test = kpca.transform(X_test)