mirror of
https://github.com/fenago/data-science.git
synced 2026-11-07 14:36:42 +00:00
28 KiB
28 KiB
In [0]:
import matplotlib.pyplot as pltIn [0]:
# list of all xs
x = list(range(1, 11))In [10]:
print(x)[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
In [0]:
# pmf
p_X_x = [1/len(x)] * len(x)In [12]:
# sums to
print(p_X_x)[0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1]
In [13]:
plt.bar(x, p_X_x)
plt.xlabel('X')
plt.ylabel('P(X=x)')Out [13]:
Text(0, 0.5, 'P(X=x)')
In [0]:
import numpy as np
import scipy.stats as statsIn [0]:
# range of xs
x = np.linspace(-10, 10, 100)In [0]:
# 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 [19]:
plt.plot(x,p_X_1, color='blue')
plt.plot(x, p_X_2, color='orange')
plt.xlabel('X')
plt.ylabel('P(X)')Out [19]:
Text(0, 0.5, 'P(X)')