简体   繁体   English

计算百分比的加权平均值

[英]Calculate weighted average of percentages

I have a problem to solve in order to make the correct calculations.为了进行正确的计算,我有一个问题要解决。 I have a list of percentages for the performance of a specific marketing channel before and after specific actions and I want to make the percentage increment.我有一个特定营销渠道在特定行动之前和之后的绩效百分比列表,我想增加百分比。 I can't just take the average of the following values I have to take the weighted average of the values.我不能只取以下值的平均值,我必须取这些值的加权平均值。

Values below are percentages ( 0.10 is 10% )下面的值是百分比( 0.10 是 10% )

percentage_list_after_actions = [ 0.10, 0.3, 0.16, 0.22 ] 
percentage_list_before_actions = [ 0.14, 0.26, 0.12, 0.25 ]

Which is the best way of doing that?最好的方法是什么?

Is the weighted average the correct metric as we have percentages or I have to take the moving_average/rolling_average?加权平均值是正确的指标,因为我们有百分比还是我必须采用移动平均/滚动平均?

Create the function that calculates this.创建计算此值的 function。

def weighted_average_m1(distribution, weights):
  
    numerator = sum([distribution[i]*weights[i] for i in range(len(distribution))])
    denominator = sum(weights)
    
    return round(numerator/denominator,2)

weighted_average_m1(distribution, weights)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM