12.1 原始线性模型
接下来用用代码建立一个:
def make_prediction(input_row,coefficients):
# 预测值初始化为第一个系数值
out_put_y_hat = coefficients[0]
for i in range(len(input_row)-1):
out_put_y_hat += coefficients[i+1]*input_row[i]
return out_put_y_hat
# 主函数
if '__main__' == __name__:
test_dataset = [[1,1],[2,3],[4,3],[3,2],[5,5]]
test_coefficients = [0.4,0.8]
for row in test_dataset:
y_hat = make_prediction(row, test_coefficients)
print("True_Y_value = %.3f, our_prediction = %.3f"%(row[-1],y_hat))
12.2 梯度下降优化
epochs:次数,我们这个模型不断通过学习training data,不断进行迭代更新coefficient