Answers for "pca in 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

pca python

from sklearn.decomposition import PCA

pca = PCA(n_components=3)
pca.fit(features)
features_pca = pca.transform(features)
print("original shape:   ", features.shape)
print("transformed shape:", features_pca.shape)
print(pca.explained_variance_)
print(pca.explained_variance_ratio_)
Posted by: Guest on November-15-2021
0

isinstance in python

x == 1
isinstance(x<3)
  #will automatically return true or false
Posted by: Guest on March-28-2020

Python Answers by Framework

Browse Popular Code Answers by Language