This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Calculate means and normalize | |
x_mean = np.mean(X) | |
X_adj = [x-x_mean for x in X] | |
y_mean = np.mean(Y) | |
Y_adj = [y - y_mean for y in Y] | |
# Caculate Covariance Matrix | |
cov = np.cov(X_adj, Y_adj) | |
print(cov) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Define datasets | |
X = [1, 1.25, 1.8, 1.9, 2.21, 2.85] | |
Y = [1.1, 1.14, 1.8, 1.85, 2.25, 2.9] | |
print(X,Y) | |
# Let's see what this looks like | |
with plt.xkcd(): | |
plt.scatter(X, Y) | |
plt.show() |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
NewerOlder