多元回归中梯度下降算法修改

多元线性回归中,想直接给传统的MSE线性函数加两个约束。python 程序该如何实现?

原有的损失函数:

img


现在的损失函数:

img


拉格朗日乘子转换以后以后为:

img

原来的梯度下降我用的这段代码:

alpha = 0.001 
iters = 5000

def batch_gradient_descent(X,Y,theta,alpha,iters):
    cost_history = [0] * iters  # 初始化历史损失列表
    for i in range(iters):         
        prediction = np.dot(X,theta.T)                  
        theta = theta - (alpha/len(Y)) * np.dot(prediction - Y,X)   
        cost_history[i] = cost_function(X,Y,theta)
        print(theta)
    return theta,cost_history 

加入新的约束以后,现在用拉格朗日乘子法重构后的损失函数该如何表达?

请问你这些图片的出处在哪?

这不应该修改损失函数吗?

这个在优化器里不是有参数吗?

修改损失函数