Compose

AverageMerger

class mvlearn.compose.AverageMerger[source]

A transformer that computes the mean of multiview datasets

Take a multiview dataset and transform it in a single view dataset by averaging across views

n_feature_

The number of feature in each view of the input dataset Must be the same for each dataset.

Type

list of ints

n_views_

The number of views in the dataset

Type

int

See also

ConcatMerger

ConcatMerger

class mvlearn.compose.ConcatMerger[source]

A transformer that stacks features of multiview datasets.

Take a multiview dataset and transform it in a single view dataset by stacking features.

n_features_

The number of features in each view of the input dataset

Type

list of ints

n_total_features_

The number of features in the dataset, equal to the sum of n_features_

Type

int

n_views_

The number of views in the dataset

Type

int

See also

AverageMerger

RandomGaussianProjection

class mvlearn.compose.RandomGaussianProjection(n_views, n_components='auto', eps=0.1, random_state=None)[source]

Random Gaussian Projection method for constructing multiple views. Each view is constructed using sklearn's random Gaussian projection.

Parameters
  • n_views (int) -- Number of views to construct

  • n_components (int or 'auto', optional (default "auto")) -- Dimensionality of target projection space, see sklearn.random_projection.GaussianRandomProjection for details.

  • eps (float, optional (default 0.1)) -- Parameter for controlling quality of embedding when n_components = "auto" according to the Johnson-Lindenstrauss lemma A smaller value leads to a better emedding (see sklearn for details).

  • random_state (int or RandomState instance, optional (default None)) -- Controls the random sampling of Gaussian projections. Set for reproducible results.

GaussianRandomProjections_

List of GaussianRandomProjection instances fitted to construct each view.

Type

list, length n_views

Notes

From an implementation perspective, this wraps GaussianRandomProjection from sklearn.random_projection and creates multiple projections.

Examples

>>> from mvlearn.compose import RandomGaussianProjection
>>> import numpy as np
>>> X = np.random.rand(1000, 50)
>>> rgp = RandomGaussianProjection(n_views=3, n_components=10)
>>> Xs = rgp.fit_transform(X)
>>> print(len(Xs))
3
>>> print(Xs[0].shape)
(1000, 10)

Read more about sklearn's implementation here.

RandomSubspaceMethod

class mvlearn.compose.RandomSubspaceMethod(n_views, subspace_dim, random_state=None)[source]

Random Subspace Method 1 for constructing multiple views. Each view is constructed by randomly selecting features from X.

Parameters
  • n_views (int) -- Number of views to construct

  • subspace_dim (int, float) -- Number of features from the data to subsample. If float, is between 0 and 1 and denotes the proportion of features to subsample.

  • random_state (int or RandomState instance, optional (default None)) -- Controls the random sampling of features. Set for reproducible results.

n_features_

The number of features in the fitted data

Type

list, length n_views

subspace_dim_

The number of features subsampled in each view

Type

int

subspace_indices_

Feature indices to subsample for each view

Type

list of numpy.ndarray, length n_views

References

1

Tin Kam Ho. "The random subspace method for constructing decision forests." IEEE Transactions on Pattern Analysis and Machine Intelligence, 20(8):832–844, 1998.

2

Dacheng Tao, Xiaoou Tang, Xuelong Li and Xindong Wu, "Asymmetric bagging and random subspace for support vector machines-based relevance feedback in image retrieval," in IEEE Transactions on Pattern Analysis and Machine Intelligence, 28(7):1088-1099, July 2006

Examples

>>> from mvlearn.compose import RandomSubspaceMethod
>>> import numpy as np
>>> X = np.random.rand(1000, 50)
>>> rsm = RandomSubspaceMethod(n_views=3, subspace_dim=10)
>>> Xs = rsm.fit_transform(Xs)
>>> print(len(Xs))
3
>>> print(Xs[0].shape)
(1000, 10)

SimpleSplitter

class mvlearn.compose.SimpleSplitter(n_features)[source]

A transformer that splits the features of a single dataset.

Take a singleview dataset and transform it in a multiview dataset by splitting features to different views

Parameters

n_features (list of ints) -- The number of feature to keep in each split: Xs[i] will have shape (n_samples, n_features[i])

n_total_features_

The number of features in the dataset, equal to the sum of n_features_

Type

int

n_views_

The number of views in the output dataset

Type

int

See also

ConcatMerger

ViewClassifier

class mvlearn.compose.ViewClassifier(base_estimator)[source]

Apply a sklearn classifier to each view of a dataset

Build a classifier from multiview data by using one or more individual scikit-learn classifiers on each view.

Parameters

base_estimator (a sklearn classifier instance, or a list) -- Either a single sklearn classifier that will be applied to each view. One clone of the estimator will correspond to each view. Otherwise, it should be a list of estimators, of length the number of views in the multiview dataset.

n_views_

The number of views in the input dataset

Type

int

estimators_

The list of classifiers used to predict data labels. If self.base_estimator is a single estimator, this is a list containing clones of that estimator, otherwise it is one view of self.base_estimator.

Type

list of objects of length n_views_

Examples

>>> from mvlearn.datasets import load_UCImultifeature
>>> from mvlearn.compose import ViewClassifier
>>> from sklearn.linear_model import LogisticRegression
>>> Xs, y = load_UCImultifeature()
>>> clfs = ViewClassifier(LogisticRegression())
>>> y_hat = clfs.fit(Xs, y).predict(Xs)
>>> print(y_hat.shape)
(2000,)

ViewTransformer

class mvlearn.compose.ViewTransformer(base_estimator)[source]

Apply a sklearn transformer to each view of a dataset

Build a transformer from multiview dataset to multiview dataset by using one or more individual scikit-learn transformers on each view.

Parameters

base_estimator (a sklearn transformer instance, or a list) -- Either a single sklearn transformer that will be applied to each view. One clone of the estimator will correspond to each view. Otherwise, it should be a list of estimators, of length the number of views in the multiview dataset.

n_views_

The number of views in the input dataset

Type

int

estimators_

The list of transformers used to transform data. If self.base_estimator is a single transformer, it is a list containing clones of that transformer, otherwise it is a view of self.base_estimator.

Type

list of objects of length n_views_

Examples

>>> from mvlearn.datasets import load_UCImultifeature
>>> from mvlearn.compose import ViewTransformer
>>> from sklearn.decomposition import PCA
>>> Xs, _ = load_UCImultifeature()
>>> repeat = ViewTransformer(PCA(n_components=2))
>>> Xs_transformed = repeat.fit_transform(Xs)
>>> print(len(Xs_transformed))
6
>>> print(Xs_transformed[0].shape)
(2000, 2)