title: Too large variances from the covariance matrix when fitting data using curve_fit
body: <p>I have some troubles when try to fit my data using curve_fit.</p>
  
  <p>First, I have too large variances which I get from the covariance matrix: relative magnitudes of standard errors are more than 100% for some of the found parameters. However, the fit curve fits very well on the data but if I give the parameters the deviations indicated in the covariance matrix, the curve will deviate very strongly. The variances become smaller if I lower the degree of the polynomial with which I fit the data. But then the curve lays worse on the data. Another thing that puzzles me is that the initial guess for parametres does not improve the situation.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>import numpy as np
  import matplotlib.pyplot as plt
  from scipy.optimize import curve_fit 
  
  #experimental_data
  x=np.array([1842., 1885., 2149., 2164., 2195., 2208., 2234., 2254., 2266., 2284., 2292., 2315., 2334., 2350., 2361., 2381., 2387., 2427., 2435., 2458., 2484., 2498., 2563., 2592.,  830.,  269., 1498.,1918., 2100., 2112., 2312.])
  y=np.array([5336., 5401., 5852., 5882., 5945., 5976., 6030., 6074., 6096., 6143., 6164., 6217., 6267., 6305., 6334., 6383., 6402., 6507., 6533., 6599., 6678., 6717., 6929., 7032., 4358., 4047., 4916., 5461., 5770., 5791., 6234.])
  
  #fitting_function
  def f_fit(x,a,b,c,d,g):
      return a*x**4+b*x**3+c*x**2+d*x+g
  
  X=np.linspace(min(x),max(x))
  popt, pcov = curve_fit(f = f_fit, xdata= x, ydata=y)
  plt.figure(figsize=(10,7))
  plt.plot(x,y, 'x') #experimental_data
  plt.plot(X,f_fit(X, *popt))
  
  perr=np.sqrt(np.diag(pcov)) #standard errors
  #perturbed plots
  plt.plot(X,f_fit(X, *popt+perr))
  plt.plot(X,f_fit(X, *popt-perr))
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/BOKnS.png" alt="That&#39;s what i get"></p>
  
  <p>Second, If I add <code>absoulute_sigma=True</code>, I get much smaller deviations for plot. But it doesn't make any sense for me. In the least squares method we generally don't know about the uncertainty in ydata, but most of the times it works correctly. And I don't understand why adding <code>absoulute_sigma=True</code> makes the variances so much smaller.</p>
  
  <p><code>popt, pcov = curve_fit(f = f_fit, xdata= x, ydata=y)</code> leads me to such plots:</p>
  
  <p><img src="https://i.stack.imgur.com/dpxw7.png" alt="Absolute_sigma=True"></p>
  
  <p>Sorry, If my question is primitive, I am just the beginner in this.</p>