Skip to content Skip to sidebar Skip to footer

Why Am I Getting Incorrect Results From Scipy.optimize.fmin?

import pandas as pd from scipy.optimize import fmin data = pd.DataFrame({'DIV': [1,2,3]*3, 'MONTH': ['May','May','May','June','June','Jun','Jul','Jul','Jul'],

Solution 1:

scipy.optimize.fmin will pass the value it is trying to minimize as the first argument to the function. If you rewrite your function as

defe(r,c,u,s): #calculates average of the MAPEsreturn np.mean(mape(c,u,s,r))

You get the correct results

for d in range(1,4):
    div_data = data[data.DIV==d]
    c = return_array(div_data.C)
    u = return_array(div_data.U)
    s = return_array(div_data.S)
    r0 = [[1.0]]
    t = fmin(e,r0,args=(c,u,s))
    print'r:',t
Optimizationterminatedsuccessfully.Current function value:0.000011Iterations:16Function evaluations:32r: [ 0.33330078]
Optimizationterminatedsuccessfully.Current function value:0.000000Iterations:15Function evaluations:30r: [ 0.5]
Optimizationterminatedsuccessfully.Current function value:0.000000Iterations:10Function evaluations:20r: [ 1.]

Post a Comment for "Why Am I Getting Incorrect Results From Scipy.optimize.fmin?"