scipy.stats.mstats.zscore
The Z-score provides information on how far a given value deviates from the standard deviation. When a data point’s Z-score is 0, it means that it has the same score as the mean.
Z = ( Observed Value ( x ) – mean ( μ ) ) / standard deviation ( σ )
Calculate the z score for each value in the input array in comparison to the sample mean and standard deviation.
Function parameters –
Syntax:
scipy.stats.mstats.zscore(a, axis=0, ddof=0, nan_policy=’propagate’)
where,
- Input array – sample input array.
- axis ( int , float ) { # optional } – Axis along which statistics are calculated. The default axis is 0.
- ddof ( int ) { # optional } – Degrees of freedom correction in the calculation of the standard deviation. The default value of ddof is 0.
- nan_policy – { ‘propagate’,’raise’,’omit’ } { # optional ) – Handle the NAN inputs.
Returns:
- zscore – array – The z-scores of input array a, normalised by mean and standard deviation.
Python3
# importing the stats module from scipy import stats as st # the random 1D ARRAY ( dataset ) dataset = [ 0.02 , 0.5 , 0.01 , 0.33 , 0.51 , 1.0 , 0.03 ] # the random 2D ARRAY ( dataset ) nd = [[ 5.1 , 6.1 ], [ 2.1 , 3.1 ], [ 5.1 , 5.1 ],\ [ 7.1 , 9.1 ], [ 9.1 , 8.1 ], [ 8.1 , 7.1 ]] # calling the kurtosis function # 1D dataset print (st.zscore(dataset)) # calling the kurtosis function # 2D dataset print (st.zscore(nd)) |
Output:
[-0.95649434 0.46555034 -0.98612027 -0.03809048 0.49517627 1.94684689 -0.92686841] [[-0.4330127 -0.16903085] [-1.73205081 -1.69030851] [-0.4330127 -0.6761234 ] [ 0.4330127 1.35224681] [ 1.29903811 0.84515425] [ 0.8660254 0.3380617 ]]
SciPy – Stats
The scipy.stats is the SciPy sub-package. It is mainly used for probabilistic distributions and statistical operations. There is a wide range of probability functions.
There are three classes:
Class | Description |
rv_continuous | For continuous random variables, we can create specialized distribution subclasses and instances. |
rv_discrete | For discrete random variables, we can create specialized distribution subclasses and instances. |
rv_histogram | generate specific distribution histograms. |
Contact Us