{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# [AMLD'19 Learning and Processing over Networks](https://github.com/rodrigo-pena/amld2019-graph-workshop)\n", "\n", "# 3 Laplacian eigenmaps and spectral clustering\n", "\n", "In this notebook we are going to explore a graph of political similarity among members of the 50th legislature of the Swiss National Council." ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import utils\n", "import numpy as np\n", "import pandas as pd\n", "import pygsp\n", "import matplotlib as mpl\n", "import matplotlib.pylab as plt\n", "\n", "from sklearn.cluster import KMeans" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The code below loads data from the `../data/` folder and formats it in the following manner:\n", "\n", "- The dataframe `council_df` contains the names of each council member, their party affiliation and a color, attributed according to said party affiliation.\n", "- The numpy array `adjacency` constains the adjacency matrix of the graph connecting members that have had similar voting patterns. The more similarly two members voted in previous sessions (either for or against a certain bill), the larger the weight of their connection. This adjacency matrix thusly encodes, to some degree, the political similarities in the Council.\n", "\n", "Run the code below to inspect the head of the `council_df` dataframe." ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " | CouncillorName | \n", "node_idx | \n", "CouncillorId | \n", "PartyAbbreviation | \n", "Color | \n", "
---|---|---|---|---|---|
0 | \n", "Thorens Goumaz Adèle | \n", "0 | \n", "3907 | \n", "PES | \n", "forestgreen | \n", "
1 | \n", "Marra Ada | \n", "1 | \n", "3923 | \n", "PSS | \n", "r | \n", "
2 | \n", "Glauser-Zufferey Alice | \n", "2 | \n", "3883 | \n", "UDC | \n", "royalblue | \n", "
3 | \n", "Moser Tiana Angelina | \n", "3 | \n", "3897 | \n", "pvl | \n", "g | \n", "
4 | \n", "Rickli Natalie | \n", "4 | \n", "3902 | \n", "UDC | \n", "royalblue | \n", "