lets_plot.sampling_random_stratified#

lets_plot.sampling_random_stratified(n, seed=None, min_subsample=None)#

Randomly sample from each stratum (subgroup).

Parameters:
nint

Number of items to return.

seedint

Number used to initialize a pseudo random number generator.

min_subsampleint

Minimal number of items in sub sample.

Returns:
FeatureSpec

Stratified random sample specification.

Examples

 1import numpy as np
 2from lets_plot import *
 3LetsPlot.setup_html()
 4np.random.seed(27)
 5n = 1000
 6x = np.random.normal(0, 1, n)
 7y = np.random.normal(0, 1, n)
 8cond = np.random.choice(['a', 'b'], n, p=[.9, .1])
 9ggplot({'x': x, 'y': y, 'cond': cond}, aes('x', 'y', color='cond')) + \
10    geom_point(sampling=sampling_random_stratified(50, 35, min_subsample=10))