Skip to content

Instantly share code, notes, and snippets.

@Daiver
Created January 21, 2020 16:24
Show Gist options
  • Save Daiver/84b0e1ab14c461d65b709c25b6c0a214 to your computer and use it in GitHub Desktop.
Save Daiver/84b0e1ab14c461d65b709c25b6c0a214 to your computer and use it in GitHub Desktop.
import numpy as np
X = np.array([
[1, 1],
[1.5, 0],
[3, 3]
], dtype=np.float)
y = np.array([1, 2, 3], dtype=np.float)
transformation = np.array([
[10, 0],
[0, 1]
], dtype=np.float)
clambda = 0.00
H = X.T @ X + clambda * np.eye(X.shape[1])
g = X.T @ y
weights = np.linalg.solve(H, g)
error = np.linalg.norm(X @ weights - y)
print(weights)
print(error)
X = X @ transformation
H = X.T @ X + clambda * np.eye(X.shape[1])
g = X.T @ y
weights = np.linalg.solve(H, g)
error = np.linalg.norm(X @ weights - y)
print(weights)
print(weights.T @ transformation)
print(error)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment