LR.py 文件源码

python
阅读 31 收藏 0 点赞 0 评论 0

项目:MachineLearningProjects 作者: geallen 项目源码 文件源码
def computeStep(X, y, theta):
    '''YOUR CODE HERE'''
    function_result = np.array([0,0], dtype= np.float)
    m = float(len(X))

    d1 = 0.0
    d2 = 0.0
    for i in range(len(X)):
        h1 = np.dot(theta.transpose(), X[i])
        c1 = h1 - y[i]
        d1 = d1 + c1
    j1 = d1/m
    for u in range(len(X)):
        h2 = np.dot(theta.transpose(), X[u])
        c2 = (h2 - y[u]) * X[u][1]
        d2 = d2 + c2
    j2 = d2/m

    function_result[0] = j1
    function_result[1] = j2
    return function_result



# Part 4: Implement the cost function calculation
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号