sampling_fraction ¶
sampling_fraction(
fraction: float, seed: int | None = None
) -> FeatureSpec
Keep a random share of the rows (ggrust extension, not in lets_plot).
fraction=0.2 keeps 20 percent of the rows (rounded, at least one), chosen
as sampling_random chooses them.
Parameters:
-
fraction(float) –Share of the rows to keep, greater than 0 and at most 1.
-
seed(int, default:None) –Seed of the random generator.
Returns:
-
FeatureSpec–The sampling, for a layer's
sampling=.
Raises:
-
SpecError–When
fractionis not in (0, 1] (20suggests0.2). -
UnsupportedValueError–When
fractionis not a number orseednot an integer.
Examples:
>>> import numpy as np
>>> from ggrust import *
>>> rng = np.random.default_rng(1)
>>> data = {"x": rng.normal(size=10_000), "y": rng.normal(size=10_000)}
>>> plot = ggplot(data, aes("x", "y")) + geom_point(sampling=sampling_fraction(0.1))