Esempio n. 1
0
def test_quick_vis_params():
    _ = quick_visualize(
        Xs,
        labels=labels,
        title="Test",
        cmap="RdBu",
        context=None,
        show=False,
        ax_ticks=False,
        ax_labels=False,
    )
print('Single-view Concatenated NMI Score: {0:.3f}\n'.format(s_nmi))

###############################################################################
# Co-Regularized multiview spectral clustering
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
#
# Use the MultiviewSpectralClustering instance to cluster the data
m_spectral1 = MultiviewCoRegSpectralClustering(n_clusters=n_class,
                                               random_state=RANDOM_SEED,
                                               n_init=100)
m_clusters1 = m_spectral1.fit_predict(Xs)

# Compute nmi between true class labels and multi-view cluster labels
m_nmi1 = nmi_score(labels, m_clusters1)
print('Multi-view NMI Score: {0:.3f}\n'.format(m_nmi1))

###############################################################################
# Visualize Results
# ^^^^^^^^^^^^^^^^^
#
# Plots of clusters produced by multiview spectral clustering and the true
# clusters.
#
# We will display the clustering results of the Co-Regularized multiview
# spectral clustering algorithm below, along with the true class labels.

quick_visualize(Xs, labels=labels, title='Ground Truth',
                scatter_kwargs={'s': 8})
quick_visualize(Xs, labels=m_clusters1, title='Multi-view Clustering',
                scatter_kwargs={'s': 8})
Esempio n. 3
0
###############################################################################
# Load the data and labels
# ^^^^^^^^^^^^^^^^^^^^^^^^
# We can either load the entire dataset (all 10 digits) or select certain
# digits. Then, visualize in 2D.

# Load entire dataset
full_data, full_labels = load_UCImultifeature()

print("Full Dataset\n")
print("Views = " + str(len(full_data)))
print("First view shape = " + str(full_data[0].shape))
print("Labels shape = " + str(full_labels.shape))

quick_visualize(full_data, labels=full_labels, title="10-class data")

###############################################################################
# Load only 2 classes of the data
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
#
# Also, shuffle the data and set the seed for reproducibility. Then, visualize
# in 2D.

# Load only the examples labeled 0 or 1, and shuffle them,
# but set the random_state for reproducibility
partial_data, partial_labels = load_UCImultifeature(select_labeled=[0, 1],
                                                    shuffle=True,
                                                    random_state=42)

print("\n\nPartial Dataset (only 0's and 1's)\n")
# As one might do with a new dataset, we first visualize the data in 2
# dimensions. For multiview data, rather than using PCA, we use Multiview
# Multi-dimensional Scaling (MVMDS) available in the package to capture the
# common principal components across views. This is performed automatically
# within the quick_visualize function. From the unlabeled plot, it is clear
# that there may be 4 underlying clusters, so unsupervised clustering with 4
# clusters may be a natural next step in analyzing this data.

# Use all 6 views available to reduce the dimensionality, since MVMDS is not
# limited
sca_kwargs = {'alpha': 0.7, 's': 10}

quick_visualize(Xs,
                title="Unlabeled",
                ax_ticks=False,
                ax_labels=False,
                scatter_kwargs=sca_kwargs)
quick_visualize(Xs,
                labels=y,
                title="True Labels",
                ax_ticks=False,
                ax_labels=False,
                scatter_kwargs=sca_kwargs)

# As a comparison, we concatenate the views and use PCA to reduce the
# dimensionality. From the unlabeled plot, it is much less clear how many
# underlying classes there are, so PCA was not as useful for visualizing the
# data if our goal was to determine underlying clusters.

# Concatenate views to get naive single view
Esempio n. 5
0
def test_quick_vis_default():
    quick_visualize(Xs)
"""
================================================
Exploratory visualizations using quick_visualize
================================================

As a simple example, say we had high-dimensional multi-view data that we
wanted to quickly visualize before we begin our analysis. With
quick_visualize, we can easily do this. As an example, we will visualize the
UCI Multiple Features dataset.

"""

from mvlearn.plotting import quick_visualize
from mvlearn.datasets import load_UCImultifeature

###############################################################################
# View the UCI data
# ^^^^^^^^^^^^^^^^^
#
# Load 4-class data
Xs, y = load_UCImultifeature(select_labeled=[0, 1, 2, 3])

# Quickly visualize the data
quick_visualize(Xs, figsize=(5, 5))

###############################################################################
# Plot with class labels
# ^^^^^^^^^^^^^^^^^^^^^^

quick_visualize(Xs, labels=y, title='Labeled Classes', figsize=(5, 5))
==================================

Often, before beginning extensive analysis, it is a good idea to visualize
your dataset to help you understand its distribution and design algorithms.
As a simple example, say we had high-dimensional multi-view data that we
wanted to quickly visualize before we begin our analysis. With the
*quick_visualize* function, we can easily do this. As an example, we will
visualize the UCI Multiple Features dataset, which consists of 6
views of varying dimensionality.

"""

# License: MIT

from mvlearn.plotting import quick_visualize
from mvlearn.datasets import load_UCImultifeature

###############################################################################
# Visualize the Multiview Data
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
#
# While a 2D plot will never fully capture the essence of a 6-view dataset,
# this simple visualization helps us build intuition about the dataset by
# showing us that it can be projected to a nearly-separable subspace.

# Load 4-class data
Xs, y = load_UCImultifeature(select_labeled=[0, 1, 2, 3])

# Visualize the data in 2D, coloring the points by their class label (0-3)
quick_visualize(Xs, labels=y, title='Labeled Data in 2D', figsize=(5, 5))