Python curve_fit with multiple independent variables

后端 未结 6 601
广开言路
广开言路 2020-11-30 00:27

Python\'s curve_fit calculates the best-fit parameters for a function with a single independent variable, but is there a way, using curve_fit or something else,

6条回答
  •  [愿得一人]
    2020-11-30 00:56

    def func(X, a, b, c):
        x,y = X
        return np.log(a) + b*np.log(x) + c*np.log(y)
    
    # some artificially noisy data to fit
    x = np.linspace(0.1,1.1,101)
    y = np.linspace(1.,2., 101)
    a, b, c = 10., 4., 6.
    z = func((x,y), a, b, c) * 1 + np.random.random(101) / 100
    
    # initial guesses for a,b,c:
    p0 = 8., 2., 7.
    print curve_fit(func, (x,y), z, p0)
    

提交回复
热议问题