Questions tagged [weighted-average]

The weighted average or weighted mean is similar to an arithmetic mean where instead of each of the data points contributing equally to the final average, some data points contribute more than others.

If all the weights are equal, then the weighted mean is the same as the arithmetic mean.

The mathematical expression for the weighted average is

enter image description here

Read more here

476 questions
1
vote
0 answers

How to implement exponentially decreasing weighted average

I've been trying to implement a weighted average function using exponentially decreasing weights as described in this Wikipedia article. I think I'm failing! I'm a bit too thick to fill in a few of the gaps that seem to be missing from the Wikipedia…
0xbe5077ed
  • 4,565
  • 6
  • 35
  • 77
1
vote
2 answers

python pandas multiply dataframe by weights that vary with category in vectorized fashion

My problem is very similar to the one outlined here Except for that my main data frame has a category column, as do my weights: df Out[3]: Symbol var_1 var_2 var_3 var_4 Category Index …
Carl
  • 598
  • 2
  • 11
  • 25
1
vote
1 answer

calculating weighted geometric mean of a large list of numbers

I am trying to calculate a weighted geometric mean of a large list of number (about 115k numbers). Each number has a weight value of either 1, 2, or 3 assigned. There seem to be a ton of ways to calculate geometric mean ( non-weighted ), and one…
1
vote
0 answers

Rare, but crucial issue with my Poker hand evaluator

I am writing an AI to play 5 card Poker. In this version of Poker comes a point where a player is allowed to discard none, one, two or three of the cards in their hand and replace them with random ones from the deck. EVALUATING A HAND My AI can give…
KOB
  • 4,084
  • 9
  • 44
  • 88
1
vote
1 answer

R - Weighting by group size in bar charts

Lets say I have a dataframe that looks like this: groups <- floor(runif(1000, min=1, max=5)) activity <- rep(c("A1", "A2", "A3", "A4"), times= 250) endorsement <- floor(runif(1000, min=0, max=2)) value1 <- runif(1000, min=1, max=10) area <-…
Simon
  • 9,762
  • 15
  • 62
  • 119
1
vote
1 answer

Weighted Average - omit data if missing from value or weight

I have code like this >>> import pandas as pd >>> import numpy as np >>> >>> df1 = pd.DataFrame({'value':[10,20,np.nan,40], ... 'weight':[1,np.nan,3,4]}) >>> df1 value weight 0 10.0 1.0 1 20.0 NaN 2 NaN …
Bharat Sharma
  • 1,081
  • 3
  • 11
  • 23
1
vote
0 answers

DAX - 2 phased weighted average with 2 different weight measures

I have rather complex problem to expres. In DAX powerpivot I am trying to create measure which will be using two different Weighted averages in one measure based on aggregation level. The problem is complicated even more, because weight measures…
1
vote
2 answers

Get a weighted average of a filtered table

I'm looking for a solution that would give me a weighted average based on a dynamically filtered table. Here is what I have: Column A: a list of urls, Column B: numbers, Column C: percentages /page 100000 20% /brochures.htm?en …
1
vote
1 answer

Calculate A Weighted Average in SQL

Suppose I have a table that contains a number of transactions but I'd like to weight them by the number of stores in that state, is there a SQL command I can use that calculates the weighted average and not just the average (AVG())? |STATE | NUMBER…
Ally
  • 35
  • 1
  • 7
1
vote
2 answers

bootstrap samples by row of a data frame in r

I am trying to run a simple bootstrap on the rows of a data frame in r. Here is what I have worked up so far, but I'm hitting a dead end. x1 <- c(1:5) x2 <- c(6:10) y <- runif(5) z <- as.data.frame(rbind(x1, x2, y)) trial <- 10 avg <- rep(0,…
mike
  • 123
  • 2
  • 4
1
vote
0 answers

Pandas Groupby Multiple function application with weighted average

I have a DataFrame that look like this: In [55]:df Out [55]: WEIGHT TR_YTD TR_3Y_Ann Categ1 Categ2 Number 0 0.131214 -0.28 8.49 1 a 0 1 0.052092 1.69 13.70 3 b 1 2 0.045993 2.50 …
Mth Clv
  • 625
  • 1
  • 7
  • 20
1
vote
3 answers

Grading using weighted averages in php

How could I grade this test with php? I need a percentage score... I have an array of questions containing the correct / incorrect bool and the corresponding weight. Do I need to find the average of correct answers first? What would the equation…
Cybervanes
  • 29
  • 9
1
vote
1 answer

Use a KNN-regression algorithm in R

I am working on using the k nearest neighbours with a certain variable identified(test) for determining the value of this same variable of an individual with this value non-identified(test). Two possible approaches can be done then: first(easy one),…
Andres
  • 33
  • 1
  • 7
1
vote
3 answers

Weighted Average with a negative number

Let's say you need to display a graphical representation of how well a baseball team is doing (my software problem is not related to sports but...). Let say you chose that 25% of a gauge is related to the percentage of batters who hit during the…
Arthur Frankel
  • 4,695
  • 6
  • 35
  • 56
1
vote
1 answer

SUMIF inside a SUMPRODUCT?

I have a data set and I am trying to get the weighted average. I am finding the weighted average of credit scores weighted by an unpaid balance for each specific year. I was able to get the sum of all unpaid balances using a SUMIFS…
Andrew Cho
  • 11
  • 2