03 Z-score introduction#

%%html
<iframe width="700" height="400" src="https://www.youtube.com/embed/5S-Zfa-vOXs/" frameborder="0" allowfullscreen></iframe>
import numpy as np
import pandas as pd
from pandas import Series, DataFrame
import matplotlib.pyplot as plt
from scipy import stats

khanacademy

Z-score introduction fig 1

\[ Z = \frac{x - \mu}{\sigma} \]
x = np.array([2, 2, 3, 2, 5, 1, 6])
mu = np.mean(x)
sigma = np.std(x)
z_score = (x - mu) / sigma
# alternative way
z_score_ = stats.zscore(x)
z_score
array([-0.59160798, -0.59160798,  0.        , -0.59160798,  1.18321596,
       -1.18321596,  1.77482393])
z_score_
array([-0.59160798, -0.59160798,  0.        , -0.59160798,  1.18321596,
       -1.18321596,  1.77482393])
df = DataFrame({'lengths of wigned trutles (cm)': x, 'Z-score':z_score_})
df
lengths of wigned trutles (cm) Z-score
0 2 -0.591608
1 2 -0.591608
2 3 0.000000
3 2 -0.591608
4 5 1.183216
5 1 -1.183216
6 6 1.774824