机器学习第七讲--最优化

机器学习模型的优化目标

随机梯度下降(SGD)

动量法(momentum)

二阶方法

梯度下降法使用迭代公式进行参数更新

def gradient_descent(func, func_grad, x0, learning_rate=0.1, max_iteration=20):
    path_list = [x0]
    best_x = x0
    step = 0
    while step < max_iteration:
        update = -learning_rate * np.array(func_grad(best_x)[1])
        if(np.linalg.norm(update) < 1e-4):
            break
        best_x = best_x + update
        path_list.append(best_x)
        step = step + 1
    return best_x, np.array(path_list)

 

posted @ 2021-02-02 19:06  大米粒o  阅读(68)  评论(0编辑  收藏  举报