Multi-view dataset container

MultiViewDataset is the core data structure of the library: an ordered collection of views sharing one sample axis, together with optional sample labels and view names. Every estimator in polyview accepts it interchangeably with a plain list of arrays, and it adds the bookkeeping a list cannot carry — naming views, subsetting samples or views while keeping labels aligned, splitting into train and test, and saving to disk.

Core data container for multi-view datasets.

class polyview.dataset.multiviewdataset.MultiViewDataset(views: List, labels=None, view_names: List[str] | None = None)

Bases: object

Container for multi-view datasets.

Stores an ordered collection of views (2-D arrays sharing the same sample axis) together with optional sample labels and view names.

Parameters:
  • views (list of array-like of shape (n_samples, n_features_i)) – Each element is one view of the data. All views must have the same number of rows (samples).

  • labels (array-like of shape (n_samples,), optional) – Ground-truth or supervision labels, one per sample.

  • view_names (list of str, optional) – Human-readable name for each view. Defaults to ["view_0", "view_1", ...] when not provided.

views

Validated, read-only copies of the input views.

Type:

list of ndarray

labels

Sample labels, cast to a 1-D ndarray.

Type:

ndarray or None

view_names

Names assigned to each view.

Type:

list of str

n_views

Number of views.

Type:

int

n_samples

Number of samples (shared across views).

Type:

int

Examples

>>> import numpy as np
>>> from polyview.dataset.multiviewdataset import MultiViewDataset
>>> X1 = np.random.rand(100, 10)   # acoustic features
>>> X2 = np.random.rand(100, 20)   # visual features
>>> mvd = MultiViewDataset([X1, X2], view_names=["audio", "video"])
>>> mvd.n_views
2
>>> mvd.n_samples
100
>>> mvd["audio"].shape
(100, 10)
>>> train, test = mvd.train_test_split(test_size=0.2, random_state=42)
classmethod load(path: str) → MultiViewDataset

Load a dataset from a .npz file saved with save().

Parameters:

path (str)

Return type:

MultiViewDataset

save(path: str) → None

Save the dataset to a compressed .npz file.

Parameters:

path (str) – File path (the .npz extension is added automatically if absent).

subset_samples(indices) → MultiViewDataset

Return a new dataset with only the selected sample indices.

Parameters:

indices (array-like of int or bool mask) – Sample indices or boolean mask to select.

Return type:

MultiViewDataset

subset_views(keys) → MultiViewDataset

Return a new dataset with only the selected views.

Parameters:

keys (list of int or str)

Return type:

MultiViewDataset

to_numpy() → numpy.ndarray

Concatenate all views into a single array (early fusion).

Return type:

ndarray of shape (n_samples, sum(n_features))

train_test_split(test_size: float = 0.2, random_state: int | None = None, stratify: bool = False) → tuple[MultiViewDataset, MultiViewDataset]

Split the dataset into train and test subsets.

Parameters:
  • test_size (float, default=0.2) – Fraction of samples to include in the test set.

  • random_state (int, optional) – Seed for reproducibility.

  • stratify (bool, default=False) – If True and labels are present, perform stratified split.

Returns:

  • train (MultiViewDataset)

  • test (MultiViewDataset)