本文主要是介绍作业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
这篇关于作业1:梯度下降法的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!