title: Prediction Intervals for Hyperbolic Curve_Fit - SciPy
body: <p>How can I get prediction intervals / prediction bands with a SciPy's curve fitting function? </p>
  
  <p>More specifically, how do I get these prediction bands for the hyperbolic curve typically used in decline curve analysis?</p>
  
  <p>Any help would be appreciated.</p>
  
  <pre><code>import pandas as pd
  import numpy as np
  from datetime import timedelta
  from scipy.optimize import curve_fit
  
  def hyperbolic_equation(t, qi, b, di):
      return qi/((1.0+b*di*t)**(1.0/b))
  
  
  df1 = pd.DataFrame({ 'cumsum_days': [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15],
          'prod': [800, 900, 1200, 700, 600, 
                   550, 500, 650, 625, 600,
                   550, 525, 500, 400, 350]})
  
  qi = max(df1['prod'])
  
  #Hyperbolic curve fit the data to get best fit equation
  popt_hyp, pcov_hyp = curve_fit(hyperbolic_equation, df1['cumsum_days'], df1['prod'],bounds=(0, [qi,1,20]))
  
  #Passing t to estimate the coefficients:
  
  def fitted_hyperbolic_equation(t):
      return popt_hyp[0]/((1.0+popt_hyp[1]*popt_hyp[2]*t)**(1.0/popt_hyp[1]))
  
  #Creating future time to predict on:
  df2 = pd.DataFrame({ 'future_days': [16,17,18,19,20]})
  
  fitted_hyperbolic_equation(df2.future_days)
  
  16    388.259631
  17    368.389649
  18    349.754534
  19    332.264306
  20    315.836485
  </code></pre>
  
  <p>I have my future values, but how do I generate confidence / prediction bands (95%) with SciPy? Any help would be appreciated.</p>