weighted-average

pandas: groupby and variable weights

China☆狼群 提交于 2019-12-01 06:40:39
问题 I have a dataset with weights for each observation and I want to prepare weighted summaries using groupby but am rusty as to how to best do this. I think it implies a custom aggregation function. My issue is how to properly deal with not item-wise data, but group-wise data. Perhaps it means that it is best to do this in steps rather than in one go. In pseudo-code, I am looking for #first, calculate weighted value for each row: weighted jobs = weight * jobs #then, for each city, sum these

Whats the most concise way to pick a random element by weight in c#?

此生再无相见时 提交于 2019-11-30 12:12:21
Lets assume: List<element> 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 = 200; So the chance Element_1 got selected is 100/(100+50+200)=28.57% the chance Element_2 got selected is 50/(100+50+200)=14.29% the chance Element_3 got selected is 200/(100+50+200)=57.14% I know I can create a loop, calculate total, etc... What I want to learn is, whats the best way to do this by Linq in ONE line (or as short as possible), thanks. UPDATE

Whats the most concise way to pick a random element by weight in c#?

房东的猫 提交于 2019-11-29 18:03:22
问题 Lets assume: List<element> 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 = 200; So the chance Element_1 got selected is 100/(100+50+200)=28.57% the chance Element_2 got selected is 50/(100+50+200)=14.29% the chance Element_3 got selected is 200/(100+50+200)=57.14% I know I can create a loop, calculate total, etc... What I want to

How to provide most relevant results with Multiple Factor Weighted Sorting

匆匆过客 提交于 2019-11-28 15:23:39
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 ( articles ) can be up-/down-voted, and thus have a rating; they have a post date, and they're also tagged with categories. Users write the articles and can vote, and may or may not have some kind of ranking themselves (expert, etc). Probably similar to StackOverflow, right? I want to provide each user with a list of articles grouped by tag but sorted by

Display weighted mean by group in the data.frame

喜欢而已 提交于 2019-11-28 10:17:15
Issues regarding the command by and weighted.mean already exist but none was able to help solving my problem. I am new to R and am more used to data mining language than programming. I have a data frame with for each individual (observation/row) the income, education level and sample weight. I want to calculate the weighted mean of income by education level, and I want the result to be associated to each individual in a new column of my original data frame, like this: obs income education weight incomegroup 1. 1000 A 10 --> display weighted mean of income for education level A 2. 2000 B 1 -->