What does weighted sampling with replacement preserve?
choices draws with replacement using relative weights, leaving the population and its weights unchanged after each draw.
Python example and interpretation
A category with zero weight is excluded and the remaining one can recur. Nonzero weights define probabilities and do not enforce a per-batch quota.
from random import Random
Random(8).choices(['seen','missing'],weights=[3,0],k=3)Result ['seen', 'seen', 'seen']
中文
按类别权重重复抽样会改变哪些统计量?
choices 按相对权重有放回抽取,每次选择后总体及其权重保持原样。
Python 算例与适用条件
将空缺类别的权重设为零,剩余类别可被反复抽到。一般的非零权重只决定概率,不能强制每批达到固定配额。
from random import Random
Random(8).choices(['seen','missing'],weights=[3,0],k=3)结果 ['seen', 'seen', 'seen']