<jupyter_start><jupyter_text>In order to get confidence intervals for DCRNN predictions, I applied dropout at prediction time. I used 10 predictions to calculate the prediction intervals. The dropout rate was set at 20%. The reason this method works is that a neural network with dropout applied is mathematically equivalent to an approximation of a Gaussian process. get groudtruth data and 10 groups of prediction data<jupyter_code>pred_list = []
for i in range (10):
    pred_list.append(np.load('./data/'+str(i+1)+'.npz')['predictions'])
    
predictions = np.stack((pred_list[0], pred_list[1],pred_list[2], pred_list[3],pred_list[4], pred_list[5],
          pred_list[6], pred_list[7],pred_list[8], pred_list[9]))

groundtruth = np.load('./data/1.npz')['groundtruth']<jupyter_output><empty_output><jupyter_text>compute the empirical mean and std of the 10 groups of outputs<jupyter_code>t = np.arange(0, 6850, 1)
mean = np.mean(predictions, axis=0)
std = np.std(predictions, axis=0)<jupyter_output><empty_output><jupyter_text>some confidence interval plot examples<jupyter_code>fig, ax = plt.subplots(figsize=(15,6))
ax.plot(t[0:288]/12, groundtruth.T[100].T[0][0:288], label='groundtruth')
ax.plot(t[0:288]/12, mean.T[100].T[0][0:288], label='prediction', c='brown', linestyle='--', alpha=0.5)
ax.fill_between(t[0:288]/12, mean.T[100].T[0][0:288] - 2*std.T[100].T[0][0:288], 
                mean.T[100].T[0][0:288] + 2*std.T[100].T[0][0:288], label='±2σ range', color='brown', alpha=.3)
ax.set(title="24 hours prediction for the next 5 min of one LA sensor", ylabel="Speed (miles/hour)", xlabel="Time (hours)")
ax.legend();
fig, ax = plt.subplots(figsize=(15,6))
ax.plot(t[0:288]/12, groundtruth.T[100].T[2][0:288], label='groundtruth')
ax.plot(t[0:288]/12, mean.T[100].T[2][0:288], label='prediction', c='brown', linestyle='--', alpha=0.5)
ax.fill_between(t[0:288]/12, mean.T[100].T[2][0:288] - 2*std.T[100].T[2][0:288], 
                mean.T[100].T[2][0:288] + 2*std.T[100].T[2][0:288], label='±2σ range', color='brown', alpha=.3)
ax.set(title="24 hours prediction for the next 15 min of one LA sensor", ylabel="Speed (miles/hour)", xlabel="Time (hours)")
ax.legend();
fig, ax = plt.subplots(figsize=(15,6))
ax.plot(t[0:288]/12, groundtruth.T[100].T[5][0:288], label='groundtruth')
ax.plot(t[0:288]/12, mean.T[100].T[5][0:288], label='prediction', c='brown', linestyle='--', alpha=0.5)
ax.fill_between(t[0:288]/12, mean.T[100].T[5][0:288] - 2*std.T[100].T[5][0:288], 
                mean.T[100].T[5][0:288] + 2*std.T[100].T[5][0:288], label='±2σ range', color='brown', alpha=.3)
ax.set(title="24 hours prediction for the next 30 min of one LA sensor", ylabel="Speed (miles/hour)", xlabel="Time (hours)")
ax.legend();
fig, ax = plt.subplots(figsize=(15,6))
ax.plot(t[0:288]/12, groundtruth.T[100].T[11][0:288], label='groundtruth')
ax.plot(t[0:288]/12, mean.T[100].T[11][0:288], label='prediction', c='brown', linestyle='--', alpha=0.5)
ax.fill_between(t[0:288]/12, mean.T[100].T[11][0:288] - 2*std.T[100].T[11][0:288], 
                mean.T[100].T[11][0:288] + 2*std.T[100].T[11][0:288], label='±2σ range', color='brown', alpha=.3)
ax.set(title="24 hours prediction for the next hour of one LA sensor", ylabel="Speed (miles/hour)", xlabel="Time (hours)")
ax.legend();
fig, ax = plt.subplots(figsize=(15,6))
ax.plot(t/12, groundtruth.T[100].T[0], label='groundtruth')
ax.plot(t/12, mean.T[100].T[0], label='prediction', c='brown', linestyle='--', alpha=0.5)
ax.fill_between(t/12, mean.T[100].T[0] - 2*std.T[100].T[0], 
                mean.T[100].T[0] + 2*std.T[100].T[0], label='±2σ range', color='brown', alpha=.3)
ax.set(title="571 hours prediction for the next 5 min of one LA sensor", ylabel="Speed (miles/hour)", xlabel="Time (hours)")
ax.legend();<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.22149065051356334, 'fraction_numerical': 0.10323939952594154, 'mean_word_length': 5.63986013986014, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '372645', 'license': 'MIT', 'n_tokens_mistral': 1739, 'n_tokens_neox': 1494, 'n_words': 291, 'path': 'confidence_interval_plot.ipynb', 'repo_name': 'gaoliyao/DCRNN', 'size': '3797'}