generate_weights#
- obsidian.experiment.sampling.generate_weights(df, n, bias, plot_weights=False, enforce=False, replace=False)[source]#
Generates a Pandas series of weights for each datum given a particular bias.
df: DataFrame of candidates n: size of the design to pick bias: dictionary of biases in the format : {“column”: [lower_bound, upper_bound, relative_weight]}
Weight >1 increases sampling probability for in-range rows.
Weight <1 decreases it.
Weight = 0 excludes those rows entirely.
plot_weights: boolean, whether to plot distribution of weights, default False enforce: boolean, whether to force biases, default False replace: boolean, whether sampling will be done with replacement, default False.
When True, the enforce capacity check (qualifying rows >= n) is skipped because sampling n items with replacement from fewer qualifying rows is valid.
Returns: Pandas Series of normalized row weights.