weighted

Is there an efficient method of limiting sets of unique combinations of two lists in Python?

Is there an efficient method of limiting sets of unique combinations of two lists in Python? Question: I have the following code to generate each set of unique combinations between two lists. Alternatively phrased, all possible sets of matches of targets from a list of sources. from itertools import permutations def combos(sources, targets): assert len(sources) …

Total answers: 1

How to compute a weighted loop?

How to compute a weighted loop? Question: This is a portion of my data frame: df = pd.DataFrame({ ‘IBI_msec’: [652, 618, 654], ‘rate’: [92.02, 97.09, 91.74] }) I need to compute a loop that enables me to compute this logic: if 652 > 500, then bin = 92.02, and the remaining (652 – 500) goes …

Total answers: 1

Python: Weighted coefficient of variation

Python: Weighted coefficient of variation Question: How can I calculate the weighted coefficient of variation (CV) over a NumPy array in Python? It’s okay to use any popular third-party Python package for this purpose. I can calculate the CV using scipy.stats.variation, but it’s not weighted. import numpy as np from scipy.stats import variation arr = …

Total answers: 1

More efficient weighted Gini coefficient in Python

More efficient weighted Gini coefficient in Python Question: Per https://stackoverflow.com/a/48981834/1840471, this is an implementation of the weighted Gini coefficient in Python: import numpy as np def gini(x, weights=None): if weights is None: weights = np.ones_like(x) # Calculate mean absolute deviation in two steps, for weights. count = np.multiply.outer(weights, weights) mad = np.abs(np.subtract.outer(x, x) * count).sum() …

Total answers: 2

Weighted mean in numpy/python

Weighted mean in numpy/python Question: I have a big continuous array of values that ranges from (-100, 100) Now for this array I want to calculate the weighted average described here since it’s continuous I want also to set breaks for the values every 20 i.e the values should be discrete as -100 -80 -60 …

Total answers: 2

Weighted percentile using numpy

Weighted percentile using numpy Question: Is there a way to use the numpy.percentile function to compute weighted percentile? Or is anyone aware of an alternative python function to compute weighted percentile? thanks! Asked By: user308827 || Source Answers: Unfortunately, numpy doesn’t have built-in weighted functions for everything, but, you can always put something together. def …

Total answers: 12

Weighted standard deviation in NumPy

Weighted standard deviation in NumPy Question: numpy.average() has a weights option, but numpy.std() does not. Does anyone have suggestions for a workaround? Asked By: YGA || Source Answers: There doesn’t appear to be such a function in numpy/scipy yet, but there is a ticket proposing this added functionality. Included there you will find Statistics.py which …

Total answers: 7