lets_plot.sampling_random_stratified

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

Randomly sample from each stratum (subgroup).

Parameters
  • n (int) – Number of items to return.

  • seed (int) – Number used to initialize a pseudo random number generator.

  • min_subsample (int) – Minimal number of items in sub sample.

Returns

Stratified random sample specification.

Return type

FeatureSpec

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))