为什么只有两个点的“scipy.optimize.curve_fit”会引发 OptimizeWarning:无法估计参数的协方差?
Why does `scipy.optimize.curve_fit` with only two points raise OptimizeWarning: Covariance of the parameters could not be estimated?
为什么这种简单的搭配不起作用?
import numpy as np
from scipy.optimize import curve_fit
exponential = lambda x, a, b: np.exp(a * x + b)
popt, pcov = curve_fit(f=exponential, xdata=[350, 380], ydata=[48, 17], p0=[-0.01, 1])
print("a =", popt[0])
print("b =", popt[1])
输出为:
python-3.4.4\lib\site-packages\scipy\optimize\minpack.py:715:
OptimizeWarning: Covariance of the parameters could not be estimated
category=OptimizeWarning)
a = -0.03459958889505575
b = 15.981057124177402
它有效,但在计算 pcov 时:
If the Jacobian matrix at the solution doesn’t have a full rank, then ‘lm’ method returns a matrix filled with np.inf.
您属于哪种情况,因此您会看到警告消息。
为什么这种简单的搭配不起作用?
import numpy as np
from scipy.optimize import curve_fit
exponential = lambda x, a, b: np.exp(a * x + b)
popt, pcov = curve_fit(f=exponential, xdata=[350, 380], ydata=[48, 17], p0=[-0.01, 1])
print("a =", popt[0])
print("b =", popt[1])
输出为:
python-3.4.4\lib\site-packages\scipy\optimize\minpack.py:715:
OptimizeWarning: Covariance of the parameters could not be estimated
category=OptimizeWarning)
a = -0.03459958889505575
b = 15.981057124177402
它有效,但在计算 pcov 时:
If the Jacobian matrix at the solution doesn’t have a full rank, then ‘lm’ method returns a matrix filled with np.inf.
您属于哪种情况,因此您会看到警告消息。