Member-only story
A z-score is a numerical measurement that describes a value’s relationship to the mean of a group of values. The z-score is measured in standard deviations from the mean. If a score is 0, this means that the value is the same as the mean score. A score of 1 means that it is one standard deviation from the mean. Z-scores may be positive or negative: a positive z_score indicates the value is higher than the mean and a negative z-score means the value is less than the mean.
The formula for calculating the z-score can be seen below:-
where,
X is the score
Mu is the mean
Sigma is the standard deviation
In this post I intend to discuss the code to calculate the z_score. In order to calculate the z-score, the mean and standard deviation must be known, and the functions required to carry out there calculations can be found in the following Google Colab notebook:- https://colab.research.google.com/drive/18UF3voMAoVpBx1G4wLX7WqFsUwhk2sGd?usp=sharing
The psudeocode for calculating the z-score is found below:-
- Define the function, calc_zscore, which will take a list of numbers as input.
- Use the predefined function, calc_mean to calculate the mean, calling the variable x_mean.