week1.py 文件源码

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

项目:coursera_ML_in_python 作者: whyjay17 项目源码 文件源码
def computeCost(X, y, theta):
    inner = np.power(((X * theta.T) - y), 2)
    return np.sum(inner) / (2 * len(X))

#def gradientDescent(X, y, theta, alpha, iters):
#    temp = np.matrix(np.zeros(theta.shape))
#    params = int(theta.ravel().shape[1]) #flattens
#    cost = np.zeros(iters)
#
#    for i in range(iters):
#        err = (X * theta.T) - y
#        
#        for j in range(params):
#            term = np.multiply(err, X[:,j])
#            temp[0, j] = theta[0, j] - ((alpha / len(X)) * np.sum(term))
#        
#        theta = temp
#        cost[i] = computeCost(X, y, theta)
#    
#    return theta, cost
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号