Demo entry 6645052

3

   

Submitted by anonymous on Oct 09, 2017 at 01:20
Language: Python 3. Code size: 906 Bytes.

def ridge(X,y,delta2):
    tmp1=np.dot(X,X.T)
    a,b=tmp1.shape
    I = np.eye(a,b)
    tmp2=tmp1 + I*delta2
    theta = np.dot(np.dot(np.linalg.inv(tmp2),X),y)
    return theta

def plot(theta,delta):
    #fig,ax=plt.subplots()
    plt.xscale('log')
    for i in range(8):
        plt.plot(delta,theta[i],next(color),label="1")
    plt.show()
    return 0

for i in range(9):
    for j in range(50):
        trainset[i,j]=(trainset[i,j]-em_mean[i])/em_std[i]
    for k in range(47):
        testset[i,k] =(testset[i,k]-em_mean[i])/em_std[i]
np.mean(trainset,axis=1)
X=np.array(trainset[:8])
y=np.array(trainset[8])
Xtest=np.array(testset[:8])
ytest=np.array(testset[8])
testimes=21;
thetas=np.zeros((testimes, 8))
deltas=[np.exp(x/3-2)*np.exp(x/3-2) for x in range(testimes)]
for i in range(testimes):
    thetas[i]=ridge(X,y,deltas[i])
print(deltas)
plot(thetas.T,deltas)

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).