04 Mean (expected value) of a discrete random variable
04 Mean (expected value) of a discrete random variable#
%%html
<iframe width="700" height="400" src="https://www.youtube.com/embed/qafPcWNUiM8/" frameborder="0" allowfullscreen></iframe>
import numpy as np
import pandas as pd
from pandas import Series, DataFrame
import matplotlib.pyplot as plt
import seaborn as sns
from scipy import stats, special
df = DataFrame({'x': [0, 1, 2, 3, 4] ,'P(x)': [0.1, 0.15, 0.4, 0.25, 0.1]})
df
x | P(x) | |
---|---|---|
0 | 0 | 0.10 |
1 | 1 | 0.15 |
2 | 2 | 0.40 |
3 | 3 | 0.25 |
4 | 4 | 0.10 |
np.sum(df['x'] * df['P(x)'])
2.1
# Caution: linear agebra :D
np.dot(df['x'], df['P(x)'])
2.1
# scipy.norm.mean; scipy.norm.var; scipy.norm.std but how?