fengdu78 / Coursera-ML-AndrewNg-Notes

吴恩达老师的机器学习课程个人笔记
32.14k stars 10.63k forks source link

grandient函数定义疑问 #57

Open gttiankai opened 5 years ago

gttiankai commented 5 years ago

在 code 的1.linear_regreesion_v1.ipynb文件中, 关于 grandient 函数的定义不明白?

def gradient(theta, X, y):
    m = X.shape[0]

    inner = X.T @ (X @ theta - y)  # (m,n).T @ (m, 1) -> (n, 1),X @ theta等价于X.dot(theta)

    return inner / m

为什么是 inner = X.T @ (X @ theta - y)? 我看方程的定义是: image

为啥不是 inner = (theta.T @ X -y) @ X ?