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 avergae is

enter image description here

387 questions
86
votes
14 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,373
  • 4
  • 15
  • 24
32
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
  • 21,536
  • 14
  • 123
  • 183
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
  • 6,838
  • 5
  • 39
  • 58
24
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…
TrungDQ
  • 6,286
  • 3
  • 31
  • 54
13
votes
7 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
  • 26,725
  • 49
  • 190
  • 355
13
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
  • 23,776
  • 22
  • 102
  • 222
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
  • 858
  • 3
  • 11
  • 18
12
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.…
ChristineB
  • 1,283
  • 6
  • 15
  • 35
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
  • 1,934
  • 7
  • 29
  • 38
11
votes
4 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
  • 7,959
  • 17
  • 68
  • 111
11
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
  • 377
  • 1
  • 4
  • 14
10
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,510
  • 2
  • 18
  • 36
9
votes
4 answers

How to calculate scores?

This question is more related to logic than any programming language. If the question is not apt for the forum please do let me know and I will delete this. I have to write a logic to calculate scores for blogs for a Blog Award website. A blog may…
Dchucks
  • 1,131
  • 5
  • 20
  • 44
9
votes
3 answers

Similar code (for exponentially weighted deviation) is slower in Haskell than in Python

I implemented exponentially weighted moving average (ewma) in python3 and in Haskell (compiled). It takes about the same time. However when this function is applied twice, haskell version slows down unpredictably (more than 1000 times, whereas…
Ilya Prokin
  • 538
  • 5
  • 10
9
votes
1 answer

How to aggregate timeseries in Python?

I have two different timeseries with partially overlapping timestamps: import scikits.timeseries as ts from datetime import datetime a = ts.time_series([1,2,3], dates=[datetime(2010,10,20), datetime(2010,10,21), datetime(2010,10,23)], freq='D') b =…
eumiro
  • 179,099
  • 29
  • 277
  • 252
1
2 3
25 26