scipy.stats.scoreatpercentile(a, score, kind='rank')函数可以帮助我们在输入数组的给定百分位数处计算分数。
百分位数= 50时的分数是中位数。如果所需的分位数位于两个数据点之间,则根据插值的值在它们之间进行插值。
参数:
arr :[数组]输入数组。
per :[数组]我们需要得分的百分比。
limit :[元组]计算百分位数的下限和上限。
axis :[int]需要计算分数的轴。
结果:相对于数组元素的百分位数得分。
代码1:
# scoreatpercentile
from scipy import stats
import numpy as np
# 1D array
arr = [20, 2, 7, 1, 7, 7, 34, 3]
print("arr : ", arr)
print ("\nScore at 50th percentile : ",
stats.scoreatpercentile(arr, 50))
print ("\nScore at 90th percentile : ",
stats.scoreatpercentile(arr, 90))
print ("\nScore at 10th percentile : ",
stats.scoreatpercentile(arr, 10))
print ("\nScore at 100th percentile : ",
stats.scoreatpercentile(arr, 100))
pr