怎么理解梯度降维的矩阵算法
来源:1-1 课程导学
weixin_慕慕5408511
2021-09-06
https://blog.csdn.net/qq_41800366/article/details/86583789
def error_function(theta, X, y):
’’‘Error function J definition.’’'
diff = np.dot(X, theta) - y
return (1./2*m) * np.dot(np.transpose(diff), diff)
def gradient_function(theta, X, y):
’’‘Gradient of the function J definition.’’‘
diff = np.dot(X, theta) - y
return (1./m) * np.dot(np.transpose(X), diff)
def gradient_descent(X, y, alpha):
’’‘Perform gradient descent.’’'
theta = np.array([1, 1]).reshape(2, 1)
gradient = gradient_function(theta, X, y)
while not np.all(np.absolute(gradient) <= 1e-5):
theta = theta - alpha * gradient
gradient = gradient_function(theta, X, y)
return theta
写回答
1回答
-
flare_zhao
2021-09-08
主要把梯度下降法原理弄明白了,除非要自己写底层
00
相似问题