Why isn't `curve_fit` able to estimate the covariance of the parameter if the parameter fits exactly?

前端 未结 1 1547
清酒与你
清酒与你 2020-12-15 19:10

I don\'t understand curve_fit isn\'t able to estimate the covariance of the parameter, thus raising the OptimizeWarning below. The following MCVE e

相关标签:
1条回答
  • 2020-12-15 19:58

    The formula for the covariance of the parameters (Wikipedia) has the number of degrees of freedom in the denominator. The degrees of freedoms are computed as (number of data points) - (number of parameters), which is 1 - 1 = 0 in your example. And this is where SciPy checks the number of degrees of freedom before dividing by it.

    With xdata = [1, 2], ydata = [1, 2] you would get zero covariance (note that the model still fits exactly: exact fit is not the problem).

    This is the same sort of issue as sample variance being undefined if the sample size N is 1 (the formula for sample variance has (N-1) in the denominator). If we only took size=1 sample out of the population, we don't estimate the variance by zero, we know nothing about the variance.

    0 讨论(0)
提交回复
热议问题