Python PCA - Plotting Explained Variance Ratio with Matplotlib

Python

 1|  import matplotlib.pyplot as plt
 2|  
 3|  plt.figure(figsize=(10,6))
 4|  
 5|  plt.bar(x=range(0,len(X_train.columns)), 
 6|          height=pca.explained_variance_ratio_,
 7|          tick_label=X_train.columns)
 8|  
 9|  plt.title('Explained Variance Ratio')
10|  plt.ylabel('Explained Variance Ratio')
11|  plt.xlabel('Component')
12|  
13|  plt.show()
Python PCA - Plotting Explained Variance Ratio with Matplotlib
Did you find this snippet useful?

Sign up for free to to add this to your code library