# Data Science SCIPY for Gradient evaluation with optimization

0

SCIPY provide an optimize package to provide optimization to linear-gradient evaluation using multiple algorithms

## Optimization and Fit in SciPy – scipy.optimize

Optimization provides a useful algorithm for minimization of curve fitting, multidimensional or scalar, and root fitting.

```%matplotlib inline
import matplotlib.pyplot as plt
from scipy import optimize
import numpy as np
fre  = 5
#Sample rate
fre_samp = 50t = np.linspace(0, 2, 2 * fre_samp, endpoint = False )
a = np.sin(fre  * 2 * np.pi * t)def function(a):
return   a*2 + 20 * np.sin(a)
plt.plot(a, function(a))
plt.show()
#use BFGS algorithm for optimization
optimize.fmin_bfgs(function, 0) ```
```
It provides the most straightforward way of minimization for fair behaved function.
Nelder – Mead algorithm is not used for gradient evaluations because it may take a longer time to find the solution.
import numpy as np
from scipy import optimize

#define function f(x)
def f(x):
return .4*(1 - x[0])**2