Skip to content

Instantly share code, notes, and snippets.

@crhea93
Last active November 1, 2020 19:40
Show Gist options
  • Save crhea93/1ae2e4fcbb4e6b7178d30882cc95c208 to your computer and use it in GitHub Desktop.
Save crhea93/1ae2e4fcbb4e6b7178d30882cc95c208 to your computer and use it in GitHub Desktop.
lam, v = np.linalg.eig(cov)
print("Eigenvalues:")
print(lam)
print("Eigenvectors:")
print(v)
# Sort
eigvals, eigvects = (list(t) for t in zip(*sorted(zip(lam, v))))
# And now we can see what this looks like!
x_s = np.linspace(np.min(X_adj), np.max(X_adj), 10)
with plt.xkcd():
plt.scatter(X_adj, Y_adj, label='Data', alpha=0.6)
plt.plot(x_s, eigvects[0][0]/eigvects[0][1]*x_s, label='eigen 1')
plt.plot(x_s, eigvects[1][0]/eigvects[1][1]*x_s, label='eigen 2')
plt.legend()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment