Quartile search algorithm:
Quartiles are calculated using the median. If the number of records is an even number, i.e. 2n, then the first quartile (Q1) is equal to the median of n smallest records, and the third quartile (Q3) is equal to the median of n largest records.
If the number of records is odd, that is, in the form (2n + 1), then
Range: is the difference between the largest value and the smallest value in a given dataset.
Interquartile range:
Interquartile range (IQR), also called mean or mean 50% , or technically Hspread — it is the difference between the third quartile (Q3) and the first quartile (Q1). It covers the distribution center and contains 50% of the observations. IQR = Q3 — Q1
Uses :
Make a decision
Suppose that if we have two datasets and their interquartile ranges are IR1 and IR2, and if IR1 & gt; IR2, it is said that the data in IR1 has more variability than the data in IR2, and the data in IR2 is preferable.
Example :
Interquartile range using numpy.median

Output: 34.0
Interquartile range using numpy.percentile
# Import digital library
import
numpy as np
data
=
[
32
,
36
,
46
,
47
, 56
,
69
,
75
,
79
,
79
,
88
,
89
,
91
,
92
,
93 < / code> ,
96
,
97
,
101 ,
105
,
112
,
116
]
# First quartile (Q1)
Q1
=
np.percentile (data,
25
, interpolation
=
`midpoint`
)
# Third quartile (Q3)
Q3
=
np.percentile (data,
75
, interpolation
=
` midpoint`
)
# Interapartment range (IQR)
IQR
=
Q3

Q1
print
(IQR)
Output: 34.0Interquartile range using scipy.stats.iqr
# Import statistics from the Scipy library
from
scipy
import
stats
data
=
[
32
,
36
,
46
,
47
,
56
,
69
,
75
,
79
,
79
,
88
,
89
,
91
,
92
,
93
,
96
,
97
,
101
,
105
,
112
,
116
]
# Interquartile range (IQR)
IQR
=
stats.iqr (data, interpolation
=
` midpoint`
)
(IQR)
Output: 34.0< strong> Quartile Deviation
Quartile Deviation — this is half the difference between the third quartile (Q3) and the first quartile (Q1), i.e. half of the interquartile range (IQR). (Q3 — Q1) / 2 = IQR / 2Make a decision
Dataset with higher quartile deviation , has higher volatility.Quartile deflection using numpy.median
# import the numpy library as np
import
numpy as np
data
=
[
32
,
36
,
46
,
47
,
56
,
69
, 75
,
79
,
79
,
88
,
89
,
91
,
92
,
93
,
96
,
97
,
101
,
105
,
112
,
116
]
# First quartile (Q1)
Q1
=
np.median (data [:
10
])
# Third quartile (Q3)
Q3
=
np.median (data [
10
:])
# Interquartile range (IQR)
IQR
=
Q3

Q1
# Quartile Deviation
qd
=
IQR
/
2
(qd)
Output: 17.0