title: KDE Confidence Interval
body: <p>Can anyone help with below code?<a href="https://i.stack.imgur.com/4y1Cc.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/4y1Cc.png" alt="Please see the plot below I was trying to find the lower and upper limit of the distribution." /></a></p>
  <p>My code as below</p>
  <h1>In[152]:</h1>
  <pre><code>sample = kde.resample(43826)
  5 ** np.percentile(sample, 5)
  </code></pre>
  <h1>In[153]:</h1>
  <pre><code> def resample_kde_percentile(kde):
      sample = kde.resample(kde.n)
      return 5 ** np.percentile(sample, 5)
  </code></pre>
  <h1>In[154]:</h1>
  <pre><code>def summarize(t, digits=2):
       table = pd.DataFrame(columns=['Estimate', 'SE', 'CI90'])
       est = np.mean(t).round(digits)
       SE = np.std(t).round(digits)
       CI95 = np.percentile(t, [5, 95]).round(digits)
       table.loc[''] = est, SE, CI95
       return table
  </code></pre>
  <h1>In[155]:</h1>
  <pre><code>t10 = [resample_kde_percentile(kde)
     for i in range(1000)]
  
  summary10 = summarize(t10)
  summary10
  </code></pre>
  <p>I am trying to find the upper and lower limit using KDE bootstrapping.</p>
  <p>steps</p>
  <ol>
  <li>Find residual of Actual and prediction.</li>
  <li>Normalize the residuals</li>
  <li>KDE of residuals</li>
  <li>resampling  KDE</li>
  <li>find the upper and lower limit</li>
  <li>create Prediction interval.</li>
  </ol>