grassp.tl.class_balance

Contents

grassp.tl.class_balance#

class_balance(data, label_key, min_class_size=10, seed=42)[source]#

Return a balanced subset with equally sized clusters.

Samples the same number of observations from each category in data.obs[label_key] (the size is determined by the smallest class).

Parameters:
data AnnData

Input AnnData.

label_key str

Observation column with cluster or class labels.

min_class_size int (default: 10)

Raise an error if the smallest class contains fewer than this number of observations (default 10).

seed int (default: 42)

Random seed for reproducible sampling.

Return type:

AnnData

Returns:

An AnnData view containing the balanced subset.