python - How for find x for a fitted exponential function? -
fp.append(np.polyfit(train_x, train_y, 2)) f.append(np.poly1d(fp)) print(np.poly1d(fp)) threshold = fsolve(f, 50) the above code finds x values y=50 successfully. when try same fitted exponential function, can't understand how that.
def f_exp(x, a, b, c): y = * 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 :typeerror: f_exp() missing 3 required positional arguments: 'a', 'b', , 'c' if add *popt get
threshold = fsolve(f_exp(*popt), 50) fails with: typeerror: f_exp() missing 1 required positional argument: 'c' i assume need add x value, it's value i'm trying find... anyway, adding value instead of x, leads error:
threshold = fsolve(f_exp(1, *popt), 50) fails with: typeerror: 'numpy.float64' object not callable
i guess need pass f_exp function optimized parameters fsolve (i.e. a, b , c args set values obtained curve_fit). in order can use functools.partial function:
popt, pcov = curve_fit(f_exp, train_x, train_y) print(popt) import functools # preparing arguments kwargs = dict(zip(['a', 'b', 'c'], popt)) optimized_f_exp = functools.partial(f_exp, **kwargs) threshold = fsolve(optimized_f_exp, 50) what did here made new function optimized_f_exp partially fixing a, b , c args of original function popt (what's why called partial).
Comments
Post a Comment