Files
mlessentials/Lab08/Examples/distributions.ipynb
T
2021-02-05 20:44:51 +00:00

4.9 KiB

In [ ]:
import matplotlib.pyplot as plt
In [ ]:
# list of all xs
x = list(range(1, 11))
In [ ]:
print(x)
In [ ]:
# pmf
p_X_x = [1/len(x)] * len(x)
In [ ]:
# sums to 
print(p_X_x)
In [ ]:
plt.bar(x, p_X_x)
plt.xlabel('X')
plt.ylabel('P(X=x)')
In [ ]:
import numpy as np
import scipy.stats as stats
In [ ]:
# range of xs
x = np.linspace(-10, 10, 100)
In [ ]:
# first normal distribution with mean = 0, variance = 1
p_X_1 = stats.norm.pdf(x=x, loc=0.0, scale=1.0**2)

# second normal distribution with mean = 0, variance = 2.25
p_X_2 = stats.norm.pdf(x=x, loc=0.0, scale=1.5**2)
In [ ]:
plt.plot(x,p_X_1, color='blue')
plt.plot(x, p_X_2, color='orange')
plt.xlabel('X')
plt.ylabel('P(X)')