Use python to achieve gradient reduction

1. Today Xiaoguan will introduce the use of python to achieve gradient reduction

2. Come and show:

#theta = theta - alpha*(theta*X-Y)*X
theta = 1.0
#(alpha 阿尔法)
alpha = 0.1
#100次遍历
for i in range(100):
    #sum/3.0表示求加权平均值
    theta = theta + np.sum(alpha*(Y-dot(X,theta))*X)/3.0
print(theta)

3. Print the result:

 I hope I can help everyone, I ask you if you want a like, will you give it, thank you all.
Copyright statement: The copyright of this article belongs to the author (@攻城狮小关) and CSDN. Welcome to reprint, but you must keep this paragraph without the author’s consent Statement, and provide the original link in an obvious place on the article page, otherwise the right to pursue legal responsibility is reserved.
It is not easy for everyone to write articles, please respect the fruits of labor~ 
Communication plus Q: 1909561302
Blog Park Address https://www.cnblogs.com/guanguan-com/

Guess you like

Origin blog.csdn.net/Mumaren6/article/details/108689386