简体   繁体   中英

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% )

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.

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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