SHARE
TWEET

Untitled

a guest Nov 17th, 2019 73 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. def scree_plot(S, n_components=10):
  2.     """
  3.     Plot proportion of variance contained in each individual component
  4.     """
  5.     components = np.arange(n_components) + 1
  6.     S = S ** 2
  7.     total_var = np.sum(S[:n_components])
  8.     proportions = S / total_var
  9.     plt.bar(components, proportions[:n_components])
  10.     plt.title("Variance Proportions across Principal Components")
  11.     plt.xlabel("Principal Component")
  12.     plt.ylabel("Proportion")
  13.     plt.show()
  14.     # raise NotImplementedError
  15.    
  16. def plot_component_vector(V):
  17.     #     raise NotImplementedError
  18.     col = np.abs(V[0,:])
  19.     #     print("col:", col)
  20.     xvals = np.arange(V.shape[1])
  21.     plt.bar(xvals, col)
  22.     plt.title("Breakdown of First Principal Component into Features")
  23.     plt.xlabel("Feature")
  24.     plt.ylabel("Value")
  25.     plt.show()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top