Last active
October 1, 2022 03:53
-
-
Save arif9799/8a86ed1acac51f2a0cdae8ec0f04af15 to your computer and use it in GitHub Desktop.
Time Series Prediction Interval - 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 = 100 | |
sigma = 5 | |
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("Normal Distribution") | |
plt.xlabel("Weights") | |
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, 'μ', color = 'black') | |
plt.axvline(x = mu+sigma, ymin = 0, ymax = 1, color = 'grey') | |
plt.text(mu+sigma, 0, 'μ + 1σ', color = 'black') | |
plt.axvline(x = mu-sigma, ymin = 0, ymax = 1, color = 'grey') | |
plt.text(mu-sigma, 0, 'μ - 1σ', color = 'black') | |
plt.axvline(x = mu+2*sigma, ymin = 0, ymax = 1, color = 'silver') | |
plt.text(mu+2*sigma, 0, 'μ + 2σ', color = 'black') | |
plt.axvline(x = mu-2*sigma, ymin = 0, ymax = 1, color = 'silver') | |
plt.text(mu-2*sigma, 0, 'μ - 2σ', color = 'black') | |
plt.axvline(x = mu+3*sigma, ymin = 0, ymax = 1, color = 'silver', linestyle = 'dashed') | |
plt.text(mu+3*sigma, 0, 'μ + 3σ', color = 'black') | |
plt.axvline(x = mu-3*sigma, ymin = 0, ymax = 1, color = 'silver', linestyle = 'dashed') | |
plt.text(mu-3*sigma, 0, 'μ - 3σ', 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