Questions tagged [weighted]

questions about problems that use a weight function, e.g. weighted mean, weighted sampling

A weight function is a mathematical device used when performing a sum, integral, or average to give some elements more "weight" or influence on the result than other elements in the same set. The result of this application of a weight function is a weighted sum or weighted average.

Weight functions occur frequently in statistics and analysis, and are closely related to the concept of a measure. Weight functions can be employed in both discrete and continuous settings.

615 questions
2
votes
1 answer

Passing arguments dynamically in Expss tables with user-defined functions

I have a (new) question related to expss tables. I wrote a very simple UDF (that relies on few expss functions), as follows: library(expss) z_indices <- function(x, m_global, std_global, weight=NULL){ if(is.null(weight)) weight = rep(1,…
Maxence Dum.
  • 121
  • 1
  • 9
2
votes
1 answer

Weighted correlation using cov.wt and data.table by group

I have a data.table like this one: set.seed(12345) mydt <- data.table(gr1 = sample(letters[1:2], size = 100, replace = TRUE), gr2 = sample(letters[3:4], size = 100, replace = TRUE), a = rnorm(100), b = rnorm(100), weight = rnorm(100,…
panman
  • 1,179
  • 1
  • 13
  • 33
2
votes
2 answers

A weighted version of random.randint

I would like to choose a random integer between a and b (both included), with the statistical weight of c. c is a value between a and b. Which is the most efficient way to apply the weight factor c to random.randint? The closest I got was this…
maxischl
  • 579
  • 1
  • 11
  • 29
2
votes
2 answers

weighted median in spatstat package

The weighted.median() function in the spatstat package returns "10.5", when I pass the evenly weighted scores of 10, 11, & 12. I was expecting the response of "11" (which is the output of stats::median() and matrixStats::weightedMedian()). The…
wibeasley
  • 5,000
  • 3
  • 34
  • 62
2
votes
1 answer

Weighted directed graph adding an edge not working

Hi im having trouble with the selected code. Can anyone tell help me figure out why the section in bold wont work? Graph(int vertices) { int vertices; LinkedList [] adjacencylist; this.vertices = vertices; …
AlFonse
  • 21
  • 2
2
votes
0 answers

How to make user-defined callable weight function for sklearn knn?

I am trying to make custom weights for Sklearn KNN classifier, similar as here. In documentation is just briefly mentioned that you can set custom weights as a user-defined function which accepts an array of distances, and returns an array of the…
Rosa
  • 155
  • 10
2
votes
2 answers

Grouped Weighted Average in Access Query

I am trying to have a weighted average fee % of sales for each Client/Product/City combo from this data. I don't need the level of detail of sub product. My data looks like…
Juvic
  • 23
  • 3
2
votes
2 answers

Vectorize weighted arithmetics across a matrix

I was wondering if there is any way to vectorize the weighted arithmetics across matrices. e.g. for calculating the weighted mean of values below given weights: set.seed(12321) values = matrix(sample(10:40, 6, replace = TRUE), ncol = 2) weights =…
aljabadi
  • 463
  • 4
  • 16
2
votes
1 answer

weighted rolling median in data.table (r)

I know tons of functions calculate the rolling median, but I could not find anything that calculates the weighted rolling median (I found ema, but that's average). Here is what I have tried *** edited on Jan 31 2019: I have found the code works fine…
2
votes
0 answers

How can I use weighted log_loss as SCORING function for linear_model.SGDClassifier?

I am using linear_model.SGDClassifier(loss='log',class_weight='balanced') for 10 classes classification (the classes are very unbalanced). It looks like that class_weight is used only at training time (in the loss function). They are not used for…
2
votes
3 answers

Creating a mean variable, from variable names and weights supplied by vectors

Suppose I want to create a mean variable in a given dataframe based on two vectors, one specifying the names of the variables to use, and one specifying weights by which these variables should go into the mean variable: vars <- c("a", "b",…
nklsstll
  • 25
  • 5
2
votes
3 answers

Why do I get error when using class_weight in sklearn GridsearchCV SVM?

Below is my code: tuned_parameters = [ {'kernel': ['linear], 'C':[1, 10], 'class_weight': ['auto']}, {'kernel': ['rbf'], 'C':[1,10], 'class_weight':['auto']}] clf = GridSearchCV(svm.SVC(), tuned_parameters, cv=5,…
Arsalan
  • 333
  • 4
  • 14
2
votes
2 answers

How do sample weights work in classification models?

What does it mean to provide weights to each sample for classification? How does a classification algorithm like Logistic regression or SVMs use weights to emphasize certain examples more than others? I would love going into details to unpack how…
Jane Sully
  • 3,137
  • 10
  • 48
  • 87
2
votes
1 answer

Weighted average grouped by country and year

I have a code which calls several apis from the UN comtrade database iterating through years. It then appends these together into a single dataset of all reporters and years from 1991 to 2018. I am trying to then get the average of the trade value…
2
votes
2 answers

Applying the Python Pandas Exponential Weighted Average in Reverse Order

For a pandas.DataFrame example: In: cols = ['cols1', 'cols2'] In: df = pd.DataFrame({'col1': [1, 2, 3, 4], 'col2': [3, 4, 5, 6]}) Out: col1 col2 0 1 3 1 2 4 2 3 5 3 4 6 I am using the…
kel
  • 113
  • 1
  • 1
  • 6