```python
# gradient descent
# derivatives = change in value with change in arguments (indicates min, max, saddle). 
# Interested in direction of fastest decrease in cost function (-nablaC)
```


```python
import numpy as np

def gradient_descent(gradient, start, learn_rate, epoch):
    vector = start
    for _ in range(epoch):
        diff = -learn_rate * gradient(vector)
        vector += diff
    return vector
```


```python
gradient_descent(gradient=lambda v: 2 * v, start=10.0, learn_rate=0.2, epoch = 10)
```




    0.06046617599999997




```python
import matplotlib.pyplot as plt
import numpy as np

def graph(formula, x_range):  
    x = np.array(x_range)
    #^ use x as range variable
    y = formula(x)
    #^          ^call the lambda expression with x
    #| use y as function result
    plt.plot(x,y)  
    plt.show() 

graph(lambda x : (2 * x), range(-10, 10))
#     ^use a lambda expression  
```


```python
#concerned with the problem of finding the rate of change of a function with respect to the variable on which it depends
```

    Requirement already satisfied: sympy in /Users/masonkadem/opt/anaconda3/lib/python3.8/site-packages (1.6.2)
    Requirement already satisfied: mpmath>=0.19 in /Users/masonkadem/opt/anaconda3/lib/python3.8/site-packages (from sympy) (1.1.0)



```python
import numpy as np
from sklearn.metrics import mean_squared_error

def gradient_descent(X, y, learningrate = 0.05, epoch = 10):
    
    '''
   Gradient descent math
    '''
    
    m, b = 0.33, 0.48 # parameters
    log, mse = [], [] # lists to store learning process
    N = len(X) # number of samples
    
    for _ in range(epoch):
                
        f = y - (m*X + b)
    
        # Updating m and b
        m -= lr * (-2 * X.dot(f).sum() / N)
        b -= lr * (-2 * f.sum() / N)
        
        log.append((m, b))
        mse.append(mean_squared_error(y, (m*X + b)))        
    
    return m, b, log, mse
```

c04283b1f8b5fdbb6c093113486a12a14f7c9a76
ipynb
Jupyter Notebook
gradient descent.ipynb
masonkadem/mathfunctions
7733880da524be712ba8bac0632b2ca00557f387
MIT
gradient descent.ipynb
masonkadem/mathfunctions
7733880da524be712ba8bac0632b2ca00557f387
MIT
gradient descent.ipynb
masonkadem/mathfunctions
7733880da524be712ba8bac0632b2ca00557f387
MIT
Qwen/Qwen-72B
1. YES
2. YES