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
0
votes
1 answer

PyTorch weights not updating after softmax

I am using PyTorch to perform an optimisation problem, which is finding a set of weights w such that the weighted average of x (sum(w * x) / sum(w)) can be used to estimate some variables say y. Below is my pytorch's 'model', dtype =…
pe-perry
  • 2,591
  • 2
  • 22
  • 33
0
votes
0 answers

Weighted averages in R grouped by variable using dplyr

So I have a df like this: Data structure(list(ID = 1:12, Team = c(1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L), DOW = c("Monday", "Monday", "Tuesday", "Tuesday", "Wednesday", "Wednesday", "Thursday", "Thursday", "Monday", "Tuesday", "Tuesday",…
John Thomas
  • 1,075
  • 9
  • 32
0
votes
1 answer

Weighted mean dataframe with pandas

I've come across a bunch of other weighted mean pandas questions but none of them seem to do what I'm trying to do. I have the following df: Primary_Key Team Quantity Value 1 Value 2 0 A Blue 10 20 …
user356
  • 303
  • 2
  • 10
0
votes
1 answer

Get random item based on multiple weights

I'm trying to work out how to choose an item at random, based on a couple of weights. Let me explain. I have a person object which has an age group assigned, young, middle or old. This age group is a known variable. I have 3 groups, each with their…
Philip Lewis
  • 57
  • 2
  • 9
0
votes
0 answers

How to calculate the weighted mean and standard deviation of a distance matrix in R

I have 1-dimensional and 2-dimensional weighted datasets for which I need to calculate optimum bandwidths for kernel smoothing. The formula for the (rule of thumb) optimal bandwidths is So I need to be able to calculate the standard deviations of…
tzirtzi
  • 75
  • 11
0
votes
3 answers

Determine the weighted mean of different columns in a data frame

I have a data frame Mesure and I wish to determine for each row, a weighted mean like this : weighted_mean = ((mean_Mesure x nbr_Mesure) + (mean_DL x nbr_DL)) / (nbr_Mesure + nbr_DL) I know there is a weighted.mean function but I failed to obtain…
Sylvain
  • 133
  • 1
  • 10
0
votes
0 answers

I am computing a weighted average, but am getting an error that says my weights are more than one dimensional

I am trying to compute a weighted average with the code: def estimate(particles, weights): mean = np.average(particles, axis=particles[:, :], weights=weights) var = np.average((particles - mean)**2, weights, axis=0) …
0
votes
1 answer

How do i distribute the influence of different world generators to generate terrain?

My applogies for the title as I do not know the correct term for my problem. I'm using Simplex Noise (with 8 octaves) to generate a height map for my terrain. To get the terrain blend in, I calculated which biome fits the location best using a…
hampus toft
  • 55
  • 10
0
votes
0 answers

Find average score based on reviews - python

I have dataframe like this. UserID Review MovieID 0 10112 Good MOV001 1 10112 Excellent MOV002 2 10112 Average MOV003 3 10113 Good MOV001 4 10113 Bad MOV002 5 10113 Good MOV003 6 …
user13424992
0
votes
1 answer

How can I build a faster decaying average? comparing a data frame's rows date field to other rows dates

I am clumsy but adequate with python. I have referenced stack often, but this is my first question. I have built a decaying average function to act on a pandas data frame with about 10000 rows, but it takes 40 minutes to run. I would appreciate any…
btonks
  • 3
  • 1
0
votes
0 answers

Weighted Average Excel

I am trying to track the average doubling time of deaths from COVID19, how long will it be at this rate of growth before we have twice as many deaths as the day before? On a daily basis I: Look at the number of deaths that day. Calculate the…
srf58
  • 1
0
votes
1 answer

Player ranking dependent on number of played games

I have a df of players and their penalty points. It looks something like this: # playerID penalty # A 0 # B 2 # A 4 # C 2 # A 0 # B 0 # B 2 I want to get a "player rank" which…
K-tan
  • 79
  • 8
0
votes
0 answers

Weighted average with condition

I have an API call that returns an array with 'participant_timestamp', 'price', and 'size'. I am looking for help in calculating a weighted average based on subsets of different time periods within this array. I've been trying to utilize…
Jim
  • 35
  • 5
0
votes
0 answers

weighted mean R

I was wondering how I can get the weighted average of my data. I have already looked on the internet, but when I try the weighted.mean function, I keep getting the same result, so I was wondering what I am doing wrong. Below is some information of…
0
votes
1 answer

Price weighted average for adjusted for new boughts and sells in r

I'm trying to find out the final weighted mean after buys and sells of my stocks. So I am looking for a weighted average, to be adjusted by the buys and sells. This is an example of my data. I have more than one stock but I can apply to the others…