1
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
謝謝它的工作原理。到目前爲止,我還沒有理解所有的代碼行。將閱讀手冊。 –