我有两列代表相同数量的数据; 一列来自我的训练数据,另一列来自我的验证数据.
我知道如何使用以下方法有效地计算训练数据的百分位数排名:
pandas.DataFrame(training_data).rank(pct = True).values
Run Code Online (Sandbox Code Playgroud)
我的问题是,如何有效地获得相对于训练数据列的验证数据列的类似百分位数排名?也就是说,对于验证数据列中的每个值,我如何找到其百分位数相对于训练数据列中所有值的排名?
我试过这样做:
def percentrank(input_data,comparison_data):
rescaled_data = np.zeros(input_data.size)
for idx,datum in enumerate(input_data):
rescaled_data[idx] =scipy.stats.percentileofscore(comparison_data,datum)
return rescaled_data/100
Run Code Online (Sandbox Code Playgroud)
但是我不确定这是否是正确的,并且最重要的是它非常慢,因为它正在对for循环中的每个值进行大量冗余计算.
任何帮助将不胜感激!