坐标下降 - 线性回归 - 蟒蛇

时间:2018-06-12 07:12:24

标签: optimization machine-learning scikit-learn gradient-descent

作为自学练习的一部分,我将根据提供的推导实现线性回归的坐标梯度下降here, page 9-10

我一直在努力为非规范化数据找到python实现,因为以下julia implementation用于规范化数据,而Sklearn实现有一千行。

基于以下推导:

enter image description here

我在Numpy中实现了:

def coordinate_descent(theta,X,y,alpha = .03, num_iters=1000):
    '''Coordinate gradient descent for linear regression'''
    #Initialisation of useful values 
    m,n = X.shape

    for i in range(num_iters):
        for j in range(n):
            h = X @ theta 
            gradient =  (X[:,j] @ (h-y))
            theta[j] = theta[j] - alpha * gradient

    return theta 

问题:

  • 这是python numpy中的正确实现吗
  • 是否有人能够在sklearn实现中找到相应的代码行(或类似代码)?

非常感谢

0 个答案:

没有答案
相关问题