scree plot python

Solutions on MaxInterview for scree plot python by the best coders in the world

showing results for - "scree plot python"
Lochlan
02 Feb 2017
1#PCA decomposition plus scree plot in python
2import matplotlib.pyplot as plt
3import numpy as np
4from sklearn.decomposition import PCA
5
6NUM_COMPONENTS = 32
7pca = PCA(NUM_COMPONENTS)
8pca.fit(YOUR_DATA)
9YOUR_DATA_pca = pca.transform(YOUR_DATA)
10U, S, V = np.linalg.svd(YOUR_DATA_pca) 
11eigvals = S**2 / np.sum(S**2) 
12fig = plt.figure()
13sing_vals = np.arange(NUM_COMPONENTS) + 1
14plt.plot(sing_vals, eigvals, 'ro-')
15plt.title('Scree Plot')
16plt.xlabel('Principal Component')
17plt.ylabel('Eigenvalue')
18plt.grid()
19plt.show()
Renata
23 Jan 2017
1from matplotlib import pyplot as plt
2from sklearn.decomposition import PCA
3import seaborn as sns
4import pandas as pd
5
6pca = PCA.fit(X_train)
7            
8df_var_explained = pd.DataFrame(pca.explained_variance_ratio_)
9
10plt.figure(figsize=(20, 20))