fp.append(np.polyfit(train_x, train_y, 2))
f.append(np.poly1d(fp))
print(np.poly1d(fp))
threshold = fsolve(f, 50)
上述代码成功找到y = 50的x值。但是当我试图对拟合的指数函数做同样的事情时,我无法理解如何做到这一点。如何找到拟合指数函数的x?
def f_exp(x, a, b, c):
y = a * np.exp(-b * x) + c
return y
popt, pcov = curve_fit(f_exp, train_x, train_y)
print(popt)
threshold = fsolve(f_exp, 50) fails with :TypeError: f_exp() missing 3 required positional arguments: 'a', 'b', and 'c'
如果我添加* POPT然后我得到
threshold = fsolve(f_exp(*popt), 50) fails with: TypeError: f_exp() missing 1 required positional argument: 'c'
我认为我需要补充的x值,但它是我试图找到...无论如何价值,增加了一些价值代替X,导致另一个错误:
threshold = fsolve(f_exp(1, *popt), 50) fails with: TypeError: 'numpy.float64' object is not callable