前言():
{
因为工作的原因,这次更新的比较晚,以后试着跟上进度。
之后大部分的Python学习都是从《神经网络与机器学习第三版》中的习题出发的。
}
正文():
{
本次实验习题比较简单,所以主要收货是对numpy的用法的熟悉。
习题2.8():
{
代码如下:
import numpy as np
#主要函数,其完全按照书上的公式编写
def least_square_for_weight(input_data, input_label, lambda_=0): #①
data_amount=input_data.shape[0]
Rxx = [[0,0,0],
[0,0,0],
[0,0,0]]
rdx = [[0],
[0],
[0]]
i = 0
j = 0
while i < data_amount:
while j < data_amount:
Rxx = Rxx - np.reshape(np.insert(input_data[i],2,1),(3,1)) * np.insert(input_data[j],2,1)
j = j + 1
rdx = rdx - np.reshape(np.insert(input_data[i],2,1),(3,1)) * input_label[i]
i = i + 1
return np.dot(np.linalg.inv(Rxx+np.identity(3)*lambda_), r