作业1:梯度下降法
2021/9/3 23:07:02
本文主要是介绍作业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:梯度下降法的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-05-20测试人员都是画画大神,让我看看谁还不会用代码图?
- 2024-05-20年薪百万的程序员都在用的摸鱼方式……
- 2024-05-19永别了,微服务架构!
- 2024-05-15鸿蒙生态设备数量超8亿台
- 2024-05-13TiDB + ES:转转业财系统亿级数据存储优化实践
- 2024-05-09“2024鸿蒙零基础快速实战-仿抖音App开发(ArkTS版)”实战课程已上线
- 2024-05-09聊聊如何通过arthas-tunnel-server来远程管理所有需要arthas监控的应用
- 2024-05-09log4j2这么配就对了
- 2024-05-09nginx修改Content-Type
- 2024-05-09Redis多数据源,看这篇就够了