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
99
votes
13 answers

algorithm used to calculate 5 star ratings

I need to calculate 5-star ratings like the one on Amazon website. I have done enough search to find what is the best algorithm, but I am not able to get a proper answer. For example, if these are the ratings 5 star - 252 4 star - 124 3 star - 40 2…
user1241438
  • 1,533
  • 4
  • 17
  • 24
36
votes
3 answers

How to provide most relevant results with Multiple Factor Weighted Sorting

I need to provide a weighted sort on 2+ factors, ordered by "relevancy". However, the factors aren't completely isolated, in that I want one or more of the factors to affect the "urgency" (weight) of the others. Example: contributed content…
drzaus
  • 24,171
  • 16
  • 142
  • 201
28
votes
1 answer

What is Youtube comment system sorting / ranking algorithm?

Youtube provides two sorting options: Newest first and Top comments. The "Newest first" is pretty simple that we just sort the comments by their post date. But the "Top comments" seems to be a lot more complex than just sorting by "thumb…
Tony Dinh
  • 6,668
  • 5
  • 39
  • 58
25
votes
3 answers

Calculating Weighted Average with LINQ

My goal is to get a weighted average from one table, based on another tables primary key. Example Data: Table1 Key WEIGHTED_AVERAGE 0200 0 Table2 ForeignKey Length Value 0200 105 52 0200 105 60 0200 …
jsmith
  • 7,198
  • 6
  • 42
  • 59
15
votes
8 answers

How to calculate iteratively the running weighted average so that last values to weight most?

I want to implement an iterative algorithm, which calculates weighted average. The specific weight law does not matter, but it should be close to 1 for the newest values and close to 0 to the oldest. The algorithm should be iterative. i.e. it should…
Suzan Cioc
  • 29,281
  • 63
  • 213
  • 385
14
votes
2 answers

STL/ranges algorithm to calculate weighted average

Assume I have a vector of grades, where the grade is struct Grade{ const int grade; const int ECTS; // weight }; Is there a STL/range-v3 algorithm/algorithms that enable me to do this? I know I could do it with std:: accumulate with some…
NoSenseEtAl
  • 28,205
  • 28
  • 128
  • 277
14
votes
3 answers

Weighted average using numpy.average

I have an array: In [37]: bias_2e13 # our array Out[37]: [1.7277990734072355, 1.9718263893212737, 2.469657573252167, 2.869022991373125, 3.314720313010104, 4.232269039271717] The error on each value in the array is: In [38]: bias_error_2e13 #…
Srivatsan
  • 9,225
  • 13
  • 58
  • 83
14
votes
4 answers

Taking np.average while ignoring NaN's?

I have a matrix with shape (64,17) correspond to time & latitude. I want to take a weighted latitude average, which I know np.average can do because, unlike np.nanmean, which I used to average the longitudes, weights can be used in the arguments.…
Cebbie
  • 1,741
  • 6
  • 23
  • 37
13
votes
1 answer

Creating a Weighted Average - Dropping Weights for NULL values

So there's the SQL Function AVG(), which takes the average of all values in a column, ignoring all NULL values. If one needs to make a weighted average, then they'd just use SUM(value * weight)/SUM(weight) with a Group By clause. If I would want to…
Jared
  • 878
  • 3
  • 11
  • 19
12
votes
3 answers

Display weighted mean by group in the data.frame

Issues regarding the command by and weighted.mean already exist but none was able to help solving my problem. I am new to R and am more used to data mining language than programming. I have a data frame with for each individual (observation/row) the…
Elixterra
  • 281
  • 1
  • 3
  • 11
12
votes
1 answer

Calculate weighted average with pandas dataframe

I have te following pandas dataframe: data_df = pd.DataFrame({'ind':['la','p','la','la','p','g','g','la'], 'dist':[10.,5.,7.,8.,7.,2.,5.,3.], 'diff':[0.54,3.2,8.6,7.2,2.1,1.,3.5,4.5], …
Cecilia
  • 487
  • 3
  • 6
  • 14
12
votes
2 answers

How to compute weighted sum of all elements in a row in pandas?

I have a pandas data frame with multiple columns. I want to create a new column weighted_sum from the values in the row and another column vector dataframe weight weighted_sum should have the following value: row[weighted_sum] = row[col0]*weight[0]…
ask
  • 2,160
  • 7
  • 31
  • 42
11
votes
5 answers

Whats the most concise way to pick a random element by weight in c#?

Lets assume: List which element is: public class Element { int Weight { get; set; } } What I want to achieve is, select an element randomly by the weight. For example: Element_1.Weight = 100; Element_2.Weight = 50; Element_3.Weight =…
Eric Yin
  • 8,737
  • 19
  • 77
  • 118
11
votes
6 answers

Adjust items chance to be selected from a list

I have a list of items. When I create the list each item has equal chance to be selected. But as an item is selected its chance goes down while the others chance goes up. If a new item is added during the process, it should have the highest…
Thad
  • 1,518
  • 2
  • 21
  • 37
10
votes
2 answers

How to use dplyr to calculate a weighted mean of two grouped variables

I know this must be super easy, but I'm having trouble finding the right dplyr commands to do this. Let's say I want to group a dataset by two variables, and then summarize the count for each row. For this we simply have: mtcars %>% group_by(cyl,…
ds_guy
  • 143
  • 2
  • 5
1
2 3
31 32