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

Conditional Weighted Average

I'm looking to build out a conditional weighted average formula. Loan Amount Loan Term Credit Score 71100 75 636 29190 75 803 16865.89 72 569 22930.86 75 556 11663.19 72 531 In R, how would you get the loan term's weighted…
1
vote
1 answer

How can I vectorize a masked weighted average with condition using numpy?

The unvectorized code reads: import numpy as np import numpy.ma as ma np.random.seed(42) H = np.random.uniform(0.1, 1.0, size=(6,8)) r, c = H.shape mask = H.max(axis=1) > 0.95 x = np.linspace(0, 10, c) weighted_averages = ma.masked_all((r,),…
redhotsnow
  • 85
  • 8
1
vote
1 answer

MySQL: calculate weighted holdings of an ETF portfolio with the result to get one list with all holdings accumulated

I have a MySQL table with around 900 entries of different ETF holdings. Here is an example: ID ETF Name Stock Name Weighting ISIN 1 iShares Automation & Robotics XIAOMI CORP…
Jan
  • 1,180
  • 3
  • 23
  • 60
1
vote
3 answers

Why am I not able to print 32.0 instead of 32 inspite of typeconversion?

So Here's my code. the inputs are 5 10 40 30 50 20 1 2 3 4 5 I'm trying to find the weighted mean of an array of size n, vector a holding the n elements with their corresponding weights in vector b. I'm unable to understand why 32 is being…
1
vote
2 answers

How can I add trainable weights while concatenating layers

I am trying to concatenate two layers in such a way that layers are assigned trainable weights while concatenating. The idea behind this is that my model can determine which layer should be given higher weights while concatenating. I have read this…
1
vote
1 answer

Weighted mean using aggregated

Sorry for asking what might be a very basic question, but I am stuck in a conundrum and cannot seem to get out of it. I have a code that looks like Medicine Biology Business sex weights 0 1 0 1 0.5 0 0 …
Gabriele
  • 13
  • 3
1
vote
2 answers

finding average by ignoring null values from denominator in oracle sql

we have table like now we have to calculate the average on the base of weightage for col1,col2,col3,col4 as 0.5,1.0,0.5,1.0 respectively so the the formula look like ((col1*0.5)+(col2*1)+(col3*0.5)+(col4*1))/(0.5+1+0.5+1) but if the value of any…
anil tiwari
  • 195
  • 13
1
vote
1 answer

Weighted mean median quartiles in Spark

I have a Spark SQL dataframe: id Value Weights 1 2 4 1 5 2 2 1 4 2 6 2 2 9 4 3 2 4 I need to groupBy by 'id' and aggregate to get the weighted mean, median, and quartiles of the values per 'id'. What is the best way to do this?
1
vote
2 answers

Get surface weighted average of multiple columns in pandas dataframe

I want to take the surface-weighted average of the columns in my dataframe. I have two surface-columns and two U-value-columns. I want to create an extra column 'U_av' (surface-weighted-average U-value) and U_av = (A1*U1 + A2*U2) / (A1+A2). If NaN…
Matthi9000
  • 1,156
  • 3
  • 16
  • 32
1
vote
1 answer

How to apply "weighted.mean" to this dataset?

I am trying to take a weighted average of a dataset similar to the following: #dataframe df = structure(list(IR = c(-1.83661599818263, -1.00531026686364, -0.174004535544658, 0.657301195774328, 1.18696961514297, 1.71663803451162, 2.24630645388026,…
Rollo99
  • 1,601
  • 7
  • 15
1
vote
1 answer

algorithm to choose weights so that average positions will approximate target position

I have a system with a small number of particles (4-10) at fixed locations in space. I then have a single target location. I would like to assign weights to each particle so that the weighted average of the particle locations is as close as possible…
billTavis
  • 19
  • 3
1
vote
1 answer

Get weighted average summary data column in new pandas dataframe from existing dataframe based on other column-ID

Somewhat similar question to an earlier question I had here: Get summary data columns in new pandas dataframe from existing dataframe based on other column-ID However, instead of just taking the sum of datapoints, I wanted to have the weighted…
Matthi9000
  • 1,156
  • 3
  • 16
  • 32
1
vote
1 answer

How to handle weighted average for AUC and selecting the right threshold for building the confusion matrix?

I have a binary classification task, where I fit the model using XGBClassifier classifier and try to predict ’1’ and ‘0’ using the test set. In this task I have a very unbalanced data majority ‘0‘ and minority ‘1’ at training data (of coarse the…
1
vote
1 answer

Calculate running average of data recursively

I have two 2D matrices A and B, where the rows indicate trials, and columns indicate samples collected during the trial. I am in a scenario where A is available, but B is collected in real-time. I want to calculate the running average of {A and the…
1
vote
1 answer

How to have a result by group when group_by doesn't apply. Weighted averages for stocks

I want to update the weighted averages of my stocks price as buy and sell them. I found a partial solution (looking though the stack overflow: Using shift and data table to update the value of an inventory), but it doesn't group by share. My data…