Answers for "pca python"

6

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_)
Posted by: Guest on November-08-2020
1

scikit learn pca

from sklearn.decomposition import KernelPCA
kpca = KernelPCA(n_components = 2, kernel = 'rbf')
X_train = kpca.fit_transform(X_train)
X_test = kpca.transform(X_test)
Posted by: Guest on January-26-2021

Python Answers by Framework

Browse Popular Code Answers by Language