首页 > 解决方案 > Andrew Ng 的 ML 课程(在 python 中)- 对多个变量应用梯度下降,对直觉感到困惑

问题描述

我正在尝试创建具有多个变量的梯度下降方程。方程图片: https ://www.holehouse.org/mlclass/04_Linear_Regression_with_multiple_variables_files/Image%20[3].png

最终解决方案是:

theta = theta - alpha *((np.dot((np.dot(X,theta)-y), X))*(1/m)). 

我通过添加额外的“np.sum”犯了一个错误:

theta = theta - alpha *((`np.sum`(((np.dot((np.dot(X,theta)-y), X))*(1/m))))*(1/m))

我很困惑为什么解决方案不需要np.sum求和,或者求和何时发生?

标签: pythonmachine-learning

解决方案


np.dot包括相乘元素的总和。

dot(a, b)[i,j,k,m] = sum(a[i,j,:] * b[k,:,m])

检查文档


推荐阅读