Answers for "scree plot python"

0

scree plot python

#PCA decomposition plus scree plot in python
import matplotlib.pyplot as plt
import numpy as np
from sklearn.decomposition import PCA

NUM_COMPONENTS = 32
pca = PCA(NUM_COMPONENTS)
pca.fit(YOUR_DATA)
YOUR_DATA_pca = pca.transform(YOUR_DATA)
U, S, V = np.linalg.svd(YOUR_DATA_pca) 
eigvals = S**2 / np.sum(S**2) 
fig = plt.figure()
sing_vals = np.arange(NUM_COMPONENTS) + 1
plt.plot(sing_vals, eigvals, 'ro-')
plt.title('Scree Plot')
plt.xlabel('Principal Component')
plt.ylabel('Eigenvalue')
plt.grid()
plt.show()
Posted by: Guest on July-22-2021
0

scree plot sklearn

from matplotlib import pyplot as plt
from sklearn.decomposition import PCA
import seaborn as sns
import pandas as pd

pca = PCA.fit(X_train)
            
df_var_explained = pd.DataFrame(pca.explained_variance_ratio_)

plt.figure(figsize=(20, 20))
Posted by: Guest on November-08-2020

Python Answers by Framework

Browse Popular Code Answers by Language