Last active
October 1, 2022 10:53
-
-
Save arif9799/8326e70b736912b4297f7c901e1345f1 to your computer and use it in GitHub Desktop.
Time Series Prediction Interval - Standard Normal Distribution Animation Code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
!pip install --upgrade pandas | |
!pip install --upgrade pandas-datareader | |
!pip install celluloid | |
from celluloid import Camera as Cam | |
from IPython.display import HTML, clear_output | |
import pandas_datareader as pdr | |
import pandas as pd | |
from statsmodels.tsa.ar_model import AutoReg | |
from statsmodels.tools.eval_measures import rmse | |
import numpy as np | |
import seaborn as sb | |
import matplotlib.pyplot as plt | |
from matplotlib import rcParams | |
from cycler import cycler | |
import matplotlib.pyplot as plt | |
import numpy as np | |
import scipy.stats as stats | |
import math | |
mu = 0 | |
sigma = 1 | |
x = np.linspace(mu - 3*sigma, mu + 3*sigma, 100) | |
fig, ax = plt.subplots(dpi = 400) | |
cam = Cam(fig) | |
rcParams['figure.figsize'] = 17,5 | |
rcParams['axes.spines.top'] = False | |
rcParams['axes.spines.right'] = False | |
rcParams['lines.linewidth'] = 2.5 | |
plt.title("Standard Normal Distribution") | |
plt.xlabel("z-values") | |
plt.ylabel("Proportions") | |
sb.despine(right = True, top = True) | |
for i in range(len(x)): | |
plt.plot(x[0:i], stats.norm.pdf(x[0:i], mu, sigma), color = '#000080') | |
cam.snap() | |
for i in range(len(x)*5): | |
plt.plot(x, stats.norm.pdf(x, mu, sigma), color = '#000080') | |
plt.axvline(x = mu, ymin = 0, ymax = 1, color = 'black') | |
plt.text(mu, 0, 'μ = 0', color = 'black') | |
plt.axvline(x = mu+sigma, ymin = 0, ymax = 1, color = 'grey') | |
plt.text(mu+sigma, 0, 'μ + 1z', color = 'black') | |
plt.axvline(x = mu-sigma, ymin = 0, ymax = 1, color = 'grey') | |
plt.text(mu-sigma, 0, 'μ - 1z', color = 'black') | |
plt.axvline(x = mu+2*sigma, ymin = 0, ymax = 1, color = 'silver') | |
plt.text(mu+2*sigma, 0, 'μ + 2z', color = 'black') | |
plt.axvline(x = mu-2*sigma, ymin = 0, ymax = 1, color = 'silver') | |
plt.text(mu-2*sigma, 0, 'μ - 2z', color = 'black') | |
plt.axvline(x = mu+3*sigma, ymin = 0, ymax = 1, color = 'silver', linestyle = 'dashed') | |
plt.text(mu+3*sigma, 0, 'μ + 3z', color = 'black') | |
plt.axvline(x = mu-3*sigma, ymin = 0, ymax = 1, color = 'silver', linestyle = 'dashed') | |
plt.text(mu-3*sigma, 0, 'μ - 3z', color = 'black') | |
cam.snap() | |
plt.close(fig) | |
animation = cam.animate(blit=False, interval=15) | |
HTML(animation.to_html5_video()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment