경사하강법 구현입니다.

new_value = old_value - learning_rate * old_value

import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline


old_value = 10
derivative = [old_value]
# basic example : x^2
y = [old_value ** 2]

learning_rate = 0.01

for i in range(1, 1000):
    # update
    new_value = old_value - learning_rate * old_value
    
    # for plotting
    y.append(new_value ** 2)
    derivative.append(new_value)
    
    old_value = new_value
    
plt.plot(derivative, y)