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
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,189
  • 5
  • 22
  • 48
9
votes
1 answer

Weighted Average of PyTorch Tensors

I have two Pytorch tensors of the form [y11, y12] and [y21, y22]. How do I get the weighted mean of the two tensors?
Samiruddin Thunder
  • 103
  • 1
  • 2
  • 6
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
  • 684
  • 6
  • 11
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
  • 207,213
  • 34
  • 299
  • 261
8
votes
1 answer

How do I calculate the standard deviation between weighted measurements?

I have several weighted values for which I am taking a weighted average. I want to calculate a weighted standard deviation using the weighted values and weighted average. How would I modify the typical standard deviation to include weights on each…
Steven C. Howell
  • 16,902
  • 15
  • 72
  • 97
6
votes
2 answers

Pandas Weighted Stats

I have a dataframe that looks like the one below. The weight column essentially represents the frequency of each item, so that for each location the weight sum will equal to 1 Please keep in mind that this is a simplified dataset, in reality there…
Mustard Tiger
  • 3,520
  • 8
  • 43
  • 68
6
votes
0 answers

Pass weights to scipy.interpolate.griddata() function

I am trying to reconstruct an image for which I know the values are floating-point pixel positions. I'm using scipy.interpolate.griddata() to interpolate the values at each integer location and reconstruct the image. However, I also want to provide…
Nagabhushan S N
  • 6,407
  • 8
  • 44
  • 87
6
votes
4 answers

How to smooth and plot x vs weighted average of y, weighted by x?

I have a dataframe with a column of weights and one of values. I'd need: to discretise weights and, for each interval of weights, plot the weighted average of values, then to extend the same logic to another variable: discretise z, and for each…
6
votes
6 answers

Pandas rolling weighted average

I want to apply a weighted rolling average to a large timeseries, set up as a pandas dataframe, where the weights are different for each day. Here's a subset of the dataframe DF: Date v_std vertical 2010-10-01 1.909 …
elnap
  • 61
  • 1
  • 1
  • 5
6
votes
7 answers

Compute weighted averages for large numbers

I'm trying to get the weighted average of a few numbers. Basically I have: Price - 134.42 Quantity - 15236545 There can be as few as one or two or as many as fifty or sixty pairs of prices and quantities. I need to figure out the weighted…
Travis
  • 133
  • 1
  • 2
  • 5
6
votes
2 answers

How to calculate mix of 4 colors defined in CIELAB L*a*b* model?

I have 4 colors that I converted from RGB to CIELAB L*a*b* model. How can I calculate mix of these 4 colors when I have (L,a,b) for each such color? How can I calculate same mix, if I want to put weights (w1, w2, w3, w4) on such 4 colors, having 1…
Ωmega
  • 42,614
  • 34
  • 134
  • 203
5
votes
5 answers

Python - Time-weighted average Pandas, grouped by time interval

I have a time-series in a Pandas DataFrame. The timestamps can be uneven (one every 1-5 minutes), but there will always be one every 5 minutes (timestamps with minutes ending in 0,5,10,15,20,25,30,35,40,45,50,55). Example: 2017-01-01 2:05:00 …
Vincent L
  • 699
  • 2
  • 11
  • 25
5
votes
2 answers

Calculate a series of weighted means in R for groups with different weightings

I have the following dataset (simple version of my actual data), 'data', and would like to calculate weighted means for variables x1 and x2, using weightings w1 and w2 respectively, split up into two groups (groups determined by the variable…
Tina218
  • 51
  • 5
4
votes
3 answers

Calculate a weighted (Bayesian) average score/index in stored procedure?

I have an MS SQL Server 2008 database where I store places that serve food (cafés, restaurants, diners etc.). On a web site connected to this database people can rate the places on a scale from 1 to 3. On the web site there's a page where people…
tkahn
  • 1,407
  • 2
  • 21
  • 37
4
votes
3 answers

Python get weighted mean of dict keys based on dict values

I am trying to write code to find the mean of the keys in my dict, but based on the dict values. So, for example, for: d = {1:2, 2:1, 3:2} the dict keys would be: [1,1,2,3,3] I've written the following code, which works for small data sets such as…
J. B.
  • 155
  • 1
  • 8
1
2
3
31 32