如何使用Scipy curve_fit用某些参数值求解方程已知
我尝试使用Scipy Curve_fit求解方程,以获取一些未知参数的估计值。我有自变量(x)和因变量(y)和一个已知的参数(e),现在我需要找到a,b,c和d的估计值。
我使用以下代码,不确定A,B,C和D是否是使用此方法的“正确”估计值。任何建议将不胜感激。
import pandas as pd
import numpy as np
from scipy.optimize import curve_fit
np.random.seed(0)
x = np.random.randint(0, 100, 100) # known independent variable
y = np.random.randint(0, 100, 100) # known dependent variable
e = np.random.randint(0, 100, 100) # know parameter
def cubic(x, a, b, c, d, e ):
return a * x**3 + b * x**2 + c * x + d + e
(a, b, c, d, e), _ = curve_fit(cubic, x, y)
print((a, b, c, d ))
(0.00010514483118750917, -0.00810393624233341, -0.10316706291775657, -24200081.18055175)
I try to use scipy curve_fit to solve an equation in order to get the estimated value for some unknown parameters. I have the independent variable (x) and dependent variable(y) and one parameter (e) known, now I need to find the estimated value for a, b, c and d.
I used the following code and not quite sure if a, b, c, and d are the "correct" estimated value by using this approach. Any advice would be greatly appreciated.
import pandas as pd
import numpy as np
from scipy.optimize import curve_fit
np.random.seed(0)
x = np.random.randint(0, 100, 100) # known independent variable
y = np.random.randint(0, 100, 100) # known dependent variable
e = np.random.randint(0, 100, 100) # know parameter
def cubic(x, a, b, c, d, e ):
return a * x**3 + b * x**2 + c * x + d + e
(a, b, c, d, e), _ = curve_fit(cubic, x, y)
print((a, b, c, d ))
(0.00010514483118750917, -0.00810393624233341, -0.10316706291775657, -24200081.18055175)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
创建一个仅接受
a,b,c,d
的函数,并通过e
的固定值传递:您可以通过使用
**来使事情变得更加明确。 Args
和初始猜测:Create a function that only accepts
a, b, c, d
and passes in the fixed value ofe
:You can make things a bit more explicit by using
*args
and an initial guess: