Ask Your Question
0

What is the method for utilizing kwargs in scipy.optimize.curve_fit() to transmit a parameter that is not undergoing fitting?

asked 2022-08-21 11:00:00 +0000

nofretete gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2022-01-06 13:00:00 +0000

lalupa gravatar image

You can utilize kwargs in scipy.optimize.curve_fit() to transmit a parameter that is not undergoing fitting by specifying the parameter name and its value in the form of a dictionary as the keyword arguments. For example, if you want to pass a parameter "p" with a value of 5 without including it in the fitting process, you can use the following code:

import scipy.optimize as optimize

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

xdata = [1, 2, 3, 4, 5]
ydata = [1, 4, 9, 16, 25]

init_guess = [1, 1, 1]

param_dict = {'p': 5}

popt, pcov = optimize.curve_fit(func, xdata, ydata, p0=init_guess, **param_dict)

In the above example, the parameter "p" is not included in the initial guess and is not being fitted. It is transmitted as a keyword argument through the param_dict. The ** before param_dict tells the function to unpack the dictionary and use it as keyword arguments.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2022-08-21 11:00:00 +0000

Seen: 12 times

Last updated: Jan 06 '22