API Reference / base /

generators.py

Base classes for synthetic data generators.

Data generators create synthetic datasets for testing and benchmarking machine learning algorithms. Concrete generators subclass one of the task-specific bases (ClassificationGenerator, RegressionGenerator, ClusteringGenerator) and implement generate().

Classes

GeneratedData

class base.generators.GeneratedData

Container for generated data.

Attributes

X
np.ndarray of shape (n_samples, n_features)
Generated feature matrix.
y
np.ndarray of shape (n_samples,)
Generated targets (labels, values, or cluster assignments).
feature_names
list of str
Names of the generated features.
target_names
list of str
Names of the target classes or outputs.

Methods

n_samples (self) -> int

Return the number of generated samples.

n_features (self) -> int

Return the number of generated features.

DataGenerator

class base.generators.DataGenerator(ABC)

Abstract base class for data generators.

Data generators create synthetic datasets for testing and benchmarking machine learning algorithms.
Constructor
__init__(
    self,
    n_samples: int = 100,
    n_features: int = 2,
    random_state: Optional[int] = None,
)

Parameters

n_samples
int = 100
Number of samples to generate.
n_features
int = 2
Number of features.
random_state
int
Random seed for reproducibility.

Methods

generate (self) -> GeneratedData

Generate the dataset.

Returns
data
GeneratedData
Container with X, y, and metadata.
__call__ (self, return_X_y: bool=False) -> Union[GeneratedData, Tuple[np.ndarray, np.ndarray]]

Generate data by calling the generator directly.

Parameters
return_X_y
bool = False
If True, return an (X, y) tuple instead of GeneratedData.
Returns
data
GeneratedData or tuple of (np.ndarray, np.ndarray)
The generated dataset, either as a container or as (X, y).
reset (self, random_state: Optional[int]=None)

Reset the random number generator.

Parameters
random_state
int
New random seed. If None, the current seed is reused.
Returns
None
get_parameter_schema (cls) -> Dict[str, Dict[str, Any]]

Return parameter schema for this generator.

Returns
schema
dict of str to dict
Mapping of constructor parameter names to JSON-Schema-style descriptions.
__repr__ (self) -> str

Return string representation of the generator.

ClassificationGenerator

class base.generators.ClassificationGenerator(DataGenerator)

Base class for classification data generators.

Constructor
__init__(
    self,
    n_samples: int = 100,
    n_features: int = 2,
    n_classes: int = 2,
    random_state: Optional[int] = None,
)

Parameters

n_samples
int = 100
Number of samples to generate.
n_features
int = 2
Number of features.
n_classes
int = 2
Number of classes.
random_state
int
Random seed for reproducibility.

Methods

get_parameter_schema (cls) -> Dict[str, Dict[str, Any]]

Return parameter schema for this generator, including n_classes.

Returns
schema
dict of str to dict
Mapping of constructor parameter names to JSON-Schema-style descriptions.

RegressionGenerator

class base.generators.RegressionGenerator(DataGenerator)

Base class for regression data generators.

Constructor
__init__(
    self,
    n_samples: int = 100,
    n_features: int = 2,
    noise: float = 0.0,
    random_state: Optional[int] = None,
)

Parameters

n_samples
int = 100
Number of samples to generate.
n_features
int = 2
Number of features.
noise
float = 0.0
Standard deviation of Gaussian noise added to the targets.
random_state
int
Random seed for reproducibility.

Methods

get_parameter_schema (cls) -> Dict[str, Dict[str, Any]]

Return parameter schema for this generator, including noise.

Returns
schema
dict of str to dict
Mapping of constructor parameter names to JSON-Schema-style descriptions.

ClusteringGenerator

class base.generators.ClusteringGenerator(DataGenerator)

Base class for clustering data generators.

Constructor
__init__(
    self,
    n_samples: int = 100,
    n_features: int = 2,
    n_clusters: int = 3,
    random_state: Optional[int] = None,
)

Parameters

n_samples
int = 100
Number of samples to generate.
n_features
int = 2
Number of features.
n_clusters
int = 3
Number of clusters.
random_state
int
Random seed for reproducibility.

Methods

get_parameter_schema (cls) -> Dict[str, Dict[str, Any]]

Return parameter schema for this generator, including n_clusters.

Returns
schema
dict of str to dict
Mapping of constructor parameter names to JSON-Schema-style descriptions.