{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Pairplot: Visualizing High Dimensional Data\n", "\n", "This example provides how to visualize high dimensional data using the pairplot." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import graspologic\n", "\n", "import numpy as np\n", "%matplotlib inline" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Simulate a binary graph using stochastic block model\n", "The 3-block model is defined as below:\n", "\n", "\\begin{align*}\n", "n &= [50, 50, 50]\\\\\n", "P &= \n", "\\begin{bmatrix}0.5 & 0.1 & 0.05 \\\\\n", "0.1 & 0.4 & 0.15 \\\\\n", "0.05 & 0.15 & 0.3\n", "\\end{bmatrix}\n", "\\end{align*}\n", "\n", "Thus, the first 50 vertices belong to block 1, the second 50 vertices belong to block 2, and the last 50 vertices belong to block 3." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from graspologic.simulations import sbm\n", "\n", "n_communities = [50, 50, 50]\n", "p = [[0.5, 0.1, 0.05], \n", " [0.1, 0.4, 0.15], \n", " [0.05, 0.15, 0.3],]\n", "\n", "np.random.seed(2)\n", "A = sbm(n_communities, p)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Embed using adjacency spectral embedding to obtain lower dimensional representation of the graph\n", "\n", "The embedding dimension is automatically chosen. It should embed to 3 dimensions." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from graspologic.embed import AdjacencySpectralEmbed\n", "\n", "ase = AdjacencySpectralEmbed()\n", "X = ase.fit_transform(A)\n", "\n", "print(X.shape)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Use pairplot to plot the embedded data\n", "\n", "First we generate labels that correspond to blocks. We pass the labels along with the data for pair plot." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from graspologic.plot import pairplot\n", "\n", "labels = ['Block 1'] * 50 + ['Block 2'] * 50 + ['Block 3'] * 50\n", "\n", "plot = pairplot(X, labels)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.7.3" } }, "nbformat": 4, "nbformat_minor": 4 }