Random Subspace

Generate multiple random-subspace views from a single feature matrix.

class polyview.augmentation.random_subspace.RandomSubspaceViews(*args: Any, **kwargs: Any)

Bases: BaseEstimator

Generate multiple random-subspace views from a single matrix.

Random subspace method creates new views by randomly selecting subsets of features (without replacement) from the original feature space. Unlike random projections which create weighted combinations, random subspaces preserve the original features but use only a subset.

Parameters:
  • n_views (int, default=2) – Number of random subspace views to generate.

  • n_features_per_view (int, optional) – Number of features to select for each view. If None, defaults to approximately sqrt(n_features) following Ho (1998).

  • random_state (int or None, default=None) – Random seed for reproducibility.

  • view_names (sequence of str, optional) – Names for each view. If None, defaults to [“view_0”, “view_1”, …].

feature_indices_

Indices of selected features for each view.

Type:

list of ndarray

n_features_in_

Number of features in the input data.

Type:

int

n_views_in_

Number of views generated (equals n_views).

Type:

int

view_names_

Names of each view.

Type:

list of str

.. rubric:: References
- Ho, T. K. (1998). The random subspace method for constructing decision forests.

IEEE Transactions on Pattern Analysis and Machine Intelligence.

Examples

>>> import numpy as np
>>> from polyview.augmentation.random_subspace import RandomSubspaceViews
>>> X = np.random.rand(100, 20)
>>> rsv = RandomSubspaceViews(n_views=3, n_features_per_view=10, random_state=0)
>>> mvd = rsv.fit_transform(X)
>>> len(mvd.views)
3
>>> mvd.views[0].shape
(100, 10)

Notes

This transformer is pipeline-friendly: it accepts a single 2-D matrix and outputs a MultiViewDataset containing n_views independent random subspace projections of the input.

fit(X, y=None) RandomSubspaceViews
fit_transform(X, y=None) MultiViewDataset
transform(X) MultiViewDataset
polyview.augmentation.random_subspace.random_subspace(X: numpy.ndarray | Sequence[Sequence[float]], n_views: int = 2, n_features_per_view: int | None = None, random_state: int | None = None, labels=None, view_names: Sequence[str] | None = None) MultiViewDataset

Create multiple random-subspace views from a single 2-D matrix.

This helper is equivalent to instantiating RandomSubspaceViews and calling fit_transform.

Parameters:
  • X (array-like of shape (n_samples, n_features)) – Input data matrix.

  • n_views (int, default=2) – Number of random subspace views.

  • n_features_per_view (int, optional) – Number of features per view. If None, defaults to sqrt(n_features).

  • random_state (int or None, default=None) – Random seed.

  • labels (array-like of shape (n_samples,), optional) – Optional ground-truth labels (attached to result).

  • view_names (sequence of str, optional) – Names for each view.

Returns:

Dataset containing n_views random-subspace views.

Return type:

MultiViewDataset