程序员的AI-2

梯度下降

image-20250212222238729

损失函数

​ 损失函数就是表示预测和实际的偏差

image-20250119193920070

MSE均方差是常见的损失函数

梯度下降

​ 有了损失函数但还需要调整权重和偏置,就可以用梯度下降的方法。替代上面线性回归算法练。

1
2
3
4
5
6
7
8
9
10
11
12
13
class LinearRegression(object):
def __init__(self, eta=0.01, iterations=10);
self.lr = eta
self.iterations = iterations
self.w = 0.0
self.bias = 0.0

def cost_function(self, X, Y, weight, bias):
n = len(X)
total_error = 0.0
for i in range(n) :
total_error = 0.0


程序员的AI-2
http://witbit.cn/AI/程序员AI入门教程/程序员的AI-2.梯度下降.html
作者
朝彻
发布于
2025年9月1日
许可协议