作业1:梯度下降法
作者:互联网
import numpy as np
import matplotlib.pyplot as plt
x = np.array([[2104, 3], [1600, 3], [2400, 3], [1416, 2],[3000,4]])
t = np.array([400, 330, 365, 232, 540])
a = 0.1
b0 = np.random.random()
b1 = np.random.random()
b2 = np.random.random()
b = np.array([theta1, theta2])
eps = 1e-5
t0 = 999
t1 = 999
t2 = 999
while t0 >= eps or t1 >= eps or t2 >= eps:
i = 0
t0 = (np.sum((x[:, i] * b[i])) + b0 * 1 - t[i])
t1 = t0 * x[1, i]
t2 = t0 * x[2, i]
b0 = b0 - a * t0
b1 = b1 - a * t1
b2 = b2 - a * t2
i += 1
print(b0, b1, b2)
11153087938.716803 17844940701444.758 26767411052167.195
标签:梯度,random,作业,t0,b0,下降,b2,np,b1 来源: https://blog.csdn.net/qq_42994498/article/details/120091904