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,

  1. Input array – sample input array.
  2. axis ( int , float ) { # optional } – Axis along which statistics are calculated. The default axis is 0.
  3. ddof ( int ) { # optional } – Degrees of freedom correction in the calculation of the standard deviation. The default value of ddof is 0.
  4. 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_continuousFor continuous random variables, we can create specialized distribution subclasses and instances.
rv_discreteFor discrete random variables, we can create specialized distribution subclasses and instances.
rv_histogramgenerate specific distribution histograms.

Similar Reads

Continuous Random Variables

A continuous random variable is a probability distribution when the random variable X can have any value. The mean is defined by the location (loc) keyword. The standard deviation is determined by the scale (scale) keyword....

Discrete Random Variables

...

Result analysis

Only a countable number of values can be assigned to discrete random variables. L is an additional integer parameter that can be added to any discrete distribution. The general distribution p and the standard distribution p0 have the following relationship:...

scipy.stats.kurtosis

...

scipy.stats.mstats.zscore

...

scipy.stats.skew

...

scipy.stats.energy_distance

...

scipy.stats.mode

...

scipy.stats.variation

Kurtosis quantifies how much of a probability distribution’s data are concentrated towards the mean as opposed to the tails....

scipy.stats.rankdata

...