Skip to content

Instantly share code, notes, and snippets.

@dissagaliyeva
Last active January 25, 2022 07:52
Show Gist options
  • Save dissagaliyeva/379b5645aea373546ce3c83ed1844a06 to your computer and use it in GitHub Desktop.
Save dissagaliyeva/379b5645aea373546ce3c83ed1844a06 to your computer and use it in GitHub Desktop.
from scipy import stats
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
sns.set() # for aesthetic purposes
def viz(mu, std, min, max, score=None):
# draw a sample
dist = np.random.normal(mu, std, size=10000)
plt.hist(dist, bins=50, density=True, range=(min, max))
plt.xlabel('SAT score'); plt.ylabel('density')
plt.axvline(score, color='red', label='my score', linewidth=3)
plt.axvline(mu, color='black', label='mean', linewidth=3)
plt.legend(loc='best')
plt.show()
# 1. calculate z-score
def calc_zscore(x, mu, std):
return (x - mu) / std
# define mu, std, my_score, min and max
my_score, mu, std = 1200, 1060, 195
min, max = 400, 1600
my_zscore = calc_zscore(my_score, mu, std)
print(f'My score {my_score}={my_zscore}')
# 2. visualize
viz(mu, std, min, max, score=my_score)
viz(0, 1, min=-3, max=3, score=my_zscore)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment