This commit is contained in:
4448445@qq.com 2021-12-28 22:52:39 +08:00
parent b62283cb55
commit 96201641f1
1 changed files with 18 additions and 0 deletions

18
梯度下降/test.py Normal file
View File

@ -0,0 +1,18 @@
def f(x):
return (x-6)**2 -3
def df(x):
return 2*(x-6)
if __name__ == '__main__':
x0 = 14
y = []
step = 400
lr = 0.01
x = x0
for i in range(step):
x = x-df(x)*lr
y.append(f(x))
print(y)