Fitting only one parameter of a function with many parameters in python

前端 未结 7 1795
隐瞒了意图╮
隐瞒了意图╮ 2020-12-01 07:55

In python I have a function which has many parameters. I want to fit this function to a data set, but using only one parameter, the rest of the parameters I want to supply o

7条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-01 08:06

    There is a simpler option if you are willing/able to edit the original function.

    Redefine your function as:

    def func(x,a):
        return a*x*x + b
    

    Then you can simply put it in your loop for parameter b:

    for b in xrange(10):
       popt,pcov = curve_fit(func, x1, x2)
    

    Caveat: the function needs to be defined in the same script in which it is called for this to work.

提交回复
热议问题