其他分享
首页 > 其他分享> > 第二次作业 9.3

第二次作业 9.3

作者:互联网

在这里插入图片描述

import numpy as np
import matplotlib.pyplot as plt
theta0 = np.array([th2, th3])
theta1 = np.random.random()
theta2 = np.random.random()
theta3 = np.random.random()
alpha = 0.0000001
x = np.array([[2104, 3], [1600, 3], [2400, 3], [1416, 2], [3000, 4]])
t = np.array([400, 330, 369, 232, 540])

eps = 1e-4
e0 = 150
e1 = 150
e2 = 150
i = 0
while e0 >= eps or e1 >= eps or e2 >= eps:
    e0 = (np.sum((x[i, 0:1] * th0[i])) + th1 * 1 - t[i])
    e1 = e0 * x[i, 0]
    e2 = e0 * x[i, 1]
    th1 = theta1 - alpha * theta0
    th2 = th2 - a * e1
    th3 = th3 - a * e2
    i +=1
print(th1, th2, th3)

0.7560097883036987 0.26594089210910343 0.07149837926879081

标签:th3,random,作业,th2,np,第二次,e1,e0,9.3
来源: https://blog.csdn.net/weixin_45997548/article/details/120083772