How do I get both lower and high 95% confidence or prediction interval columns for my prediction?
df1 = pd.DataFrame({
'cumsum_days': [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15],
'prediction': [800, 900, 1200, 700, 600,
550, 500, 650, 625, 600,
550, 525, 500, 400, 350]})
Desired dataframe looks something like this:
prediction lower_ci high_ci
800 some_num some num
900 some_num some num
1200 some_num some num
700 some_num some num
These functions only give me single digits, however I am looking for 95% confidence intervals for df.prediction (15 datapoints a piece).
mean = df.prediction.mean()
std = df.prediction.std()
I've also tried this (below), however it only gives me three values, instead of 2 additional arrays of confidence bands / intervals for my predicted values:
import numpy as np
import scipy.stats
def mean_confidence_interval(data, confidence=0.95):
a = 1.0 * np.array(data)
n = len(a)
m, se = np.mean(a), scipy.stats.sem(a)
h = se * scipy.stats.t.ppf((1 + confidence) / 2., n-1)
return m, m-h, m+h