mbi.Dataset

class mbi.Dataset(data: Mapping[Any, ndarray], domain: Domain, weights: ndarray | None = None)[source]

Bases: object

A 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

Compress the dataset by mapping domain elements to a smaller domain.

datavector

Return the database in vector-of-counts form.

decompress

Decompress the dataset by reversing the mapping.

drop

Returns a Factor with the specified columns marginalized out.

project

Project dataset onto a subset of columns.

supports

synthetic

Generate random data conforming to the given domain.

to_dict

Attributes

records

Returns the number of records (rows) in the dataset.

weights

data

domain

data: Mapping[Any, ndarray]
domain: Domain
weights: ndarray | None = None
to_dict() → dict[str | int, ndarray][source]
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.

supports(cols: str | int | Sequence[str | int]) → bool[source]
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.

datavector(flatten: bool = True) → NDArray[source]

Return the database in vector-of-counts form.

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 value i.

  • 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.