Use optimize.minimize from scipy with 2 variables and interpolated function

后端 未结 2 1473
挽巷
挽巷 2021-02-11 02:27

I didn\'t find a way to perform optimize.minimize from scipy with a multidimensional function. In nearly all examples an analytical function is optimized while my function is in

2条回答
  •  臣服心动
    2021-02-11 02:46

    One more possible solution (hope you get the idea):

    One more function is created (f), and the minimized values are sent as arguments to this function.

    from scipy.optimize import minimize
    
    x = data.Height.values
    y = data.Weight.values
    
    def f(params):
        w0, w1 = params
        return mse(w0, w1, x, y)
    
    optimum = minimize(f, (0,0), method = 'L-BFGS-B', bounds = ((-100, 100), (-5,5)) )
    w0 = optimum.x[0]
    w1 = optimum.x[1]
    

    Also tried implementation with lambda function, but had no luck.

提交回复
热议问题