mbi.Dataset
- class mbi.Dataset(data: Mapping[Any, ndarray], domain: Domain, weights: ndarray | None = None)[source]
Bases:
objectA discrete tabular dataset backed by a dictionary of 1D numpy arrays.
- Parameters:
data – Dictionary mapping attribute names to 1D integer arrays.
domain – A Domain describing the attributes and their sizes.
weights – Optional per-row weights (defaults to all ones).
Methods
__init__Compress the dataset by mapping domain elements to a smaller domain.
Return the database in vector-of-counts form.
Decompress the dataset by reversing the mapping.
Returns a Factor with the specified columns marginalized out.
Project dataset onto a subset of columns.
Generate random data conforming to the given domain.
Attributes
Returns the number of records (rows) in the dataset.
- data: Mapping[Any, ndarray]
- weights: ndarray | None = None
- static synthetic(domain: Domain, N: int) Dataset[source]
Generate random data conforming to the given domain.
- Parameters:
domain – The domain object.
N – The number of rows.
- project(cols: str | int | Sequence[str | int]) Factor[source]
Project dataset onto a subset of columns.
- drop(cols: Sequence[str | int]) Factor[source]
Returns a Factor with the specified columns marginalized out.
- property records: int
Returns the number of records (rows) in the dataset.
- compress(mapping: Mapping[Any, ndarray], labels: Mapping[Any, tuple] | None = None) Dataset[source]
Compress the dataset by mapping domain elements to a smaller domain.
- Parameters:
mapping – A dictionary where keys are attribute names and values are 1D arrays.
mapping[attr][i]gives the new value for original valuei.labels – Optional explicit labels for the compressed domain. If not provided and the domain has labels, the original labels are grouped into tuples (e.g. compressing
("cat", "dog", "bird")with mapping[0, 0, 1]gives(("cat", "dog"), ("bird",))).
- Returns:
A new Dataset with transformed values and updated domain.
- decompress(mapping: Mapping[Any, ndarray]) Dataset[source]
Decompress the dataset by reversing the mapping.
Since the mapping is surjective, the reverse mapping is one-to-many. We sample uniformly from the possible original values.
- Parameters:
mapping – The same mapping dictionary used for compression.
- Returns:
A new Dataset with restored domain size and sampled values.