Last active
October 1, 2022 03:58
-
-
Save arif9799/a2a7e00a7116f04ddf7cafcb613b9eb0 to your computer and use it in GitHub Desktop.
Time Series Prediction Interval - Standard Normal Distribution: Mr. X's reference 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() | |
weight = 170 # could be whatever the person's weight is | |
z = (weight - 110) / 30 | |
for i in np.arange(-3,z,0.1): | |
plt.plot(x, stats.norm.pdf(x, mu, sigma), color = '#000080') | |
plt.axvline(x = i, ymin = 0, ymax = 1, color = 'black') | |
plt.axvspan(-3,i, alpha = 0.1, color = 'black') | |
cam.snap() | |
for i in range(0,300): | |
plt.plot(x, stats.norm.pdf(x, mu, sigma), color = '#000080') | |
plt.axvline(x = z, ymin = 0, ymax = 1, color = 'black') | |
plt.axvspan(-3,z, alpha = 0.1, 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