updating week 39
This commit is contained in:
@@ -876,11 +876,17 @@ x = 2*np.random.rand(n,1)
|
||||
y = 4+3*x+np.random.randn(n,1)
|
||||
|
||||
X = np.c_[np.ones((n,1)), x]
|
||||
# Hessian matrix
|
||||
H = (2.0/n)* X.T @ X
|
||||
# Get the eigenvalues
|
||||
EigValues, EigVectors = np.linalg.eig(H)
|
||||
print(EigValues)
|
||||
|
||||
beta_linreg = np.linalg.inv(X.T @ X) @ X.T @ y
|
||||
print(beta_linreg)
|
||||
beta = np.random.randn(2,1)
|
||||
|
||||
eta = 0.1
|
||||
eta = 1.0/np.max(EigValues)
|
||||
Niterations = 1000
|
||||
|
||||
for iter in range(Niterations):
|
||||
@@ -968,10 +974,10 @@ import sys
|
||||
|
||||
# the number of datapoints
|
||||
n = 100
|
||||
x = 2*np.random.rand(m,1)
|
||||
y = 4+3*x+np.random.randn(m,1)
|
||||
x = 2*np.random.rand(n,1)
|
||||
y = 4+3*x+np.random.randn(n,1)
|
||||
|
||||
X = np.c_[np.ones((m,1)), x]
|
||||
X = np.c_[np.ones((n,1)), x]
|
||||
XT_X = X.T @ X
|
||||
|
||||
#Ridge parameter lambda
|
||||
|
||||
Reference in New Issue
Block a user