sampleable

class SampleableMixin

Bases: ABC

Mixin for sampleable objects.

abstract classmethod REQUIRED_COLUMNS(target=None)
Return type:

tuple[str, ...]

Parameters:

target (Literal['individual', 'dyad'] | None)

abstract annotate(observations, *, categories, background_category)

Annotate the sampleable with observations.

Parameters:
  • observations (DataFrame) – The observations to annotate the sampleable with.

  • categories (tuple[str, ...]) – The categories of the observations.

  • background_category (str) – The background category of the observations.

Return type:

AnnotatedSampleableMixin

Returns:

The annotated sampleable.

sample(extractor)

Extract features and labels (if also AnnotatedMixin) for all available samples.

Parameters:

extractor (BaseExtractor[TypeVar(F, bound= Shaped)]) – The extractor to use for sampling.

Return type:

tuple[TypeVar(F, bound= Shaped), ndarray | None]

Returns:

The extracted features and labels.

sample_X(extractor)

Extract features for all available samples.

Parameters:

extractor (BaseExtractor[TypeVar(F, bound= Shaped)]) – The extractor to use for sampling.

Return type:

TypeVar(F, bound= Shaped)

Returns:

The extracted features.

property size: int

Return the total number of available samples.

Also accessible via the len function.

subsample(extractor, size, *, random_state=None, stratify=True, reset_previous_indices=False, exclude_previous_indices=False, store_indices=False, log=None)

Extract features and labels (if also AnnotatedMixin) for a subset of samples.

Parameters:
  • extractor (BaseExtractor[TypeVar(F, bound= Shaped)]) – The extractor to use for sampling.

  • size (int | float | Mapping[str | tuple[str, ...], int | float]) – The number of samples to extract.

  • random_state (int | Generator | None, default: None) – The random state to use for sampling.

  • stratify (bool, default: True) – Whether to stratify the samples.

  • reset_previous_indices (bool, default: False) – Whether to reset the previous indices.

  • exclude_previous_indices (bool, default: False) – Whether to exclude the previous indices.

  • store_indices (bool, default: False) – Whether to store the indices.

  • log (Logger | None, default: None) – The logger to use for logging.

Return type:

tuple[TypeVar(F, bound= Shaped), ndarray | None]

Returns:

The extracted features and labels.

class SamplingFunction(*args, **kwargs)

Bases: Protocol

Protocol for functions that sample data from a sampleable.

Parameters:
  • sampleable (SampleableMixin) – The sampleable to sample from.

  • extractor (BaseExtractor) – The extractor to use for sampling.

  • *args – Additional arguments to use within the function.

  • random_state (Generator | int | None) – The random state to use for sampling.

  • log (loguru.Logger | None) – The logger to use for logging.

  • **kwargs – Additional keyword arguments to use within the function.