The “cluster of six”
This article is originally published at https://thinkr.biz
Unsupervised machine learning
Using the Hansard API (Application Programming Interface), we’ll apply unsupervised machine learning to analyze the voting patterns of 219 Labour Members of Parliament (MPs). We’ll consider all divisions (results of the votes) in the UK House of Commons since the 2017 general election.
Supervised machine learning makes predictions from labeled training data. The unsupervised flavour looks for hidden structure in “unlabeled” data, i.e. a classification or categorisation not included in the observations. Hierarchical clustering will identify a cluster of six MPs as the most “distant” from the wider party.
The full methodology, including the code, is published here. This extended narrative confirms the suitability of the data for clustering; reviews eight clustering methods for optimal fit; plots the full dendrogram of 219 Labour MPs; and rationalises the outcome in more detail, for example, using Cook’s Distance.
We’ll set a vote of “aye” to 1, and “no” to -1. And we’ll treat non-votes as 0. Voting the opposite way to the majority of the party, as well as non-votes, will be of interest when assessing which MPs are “most distant” from the majority.
The “cluster of six”
We’ll apply a “bottom up” clustering approach. Each MP starts in their own cluster, and pairs of clusters are progressively combined until none remains.
What we find is the above cluster of six MPs who, based on their voting patterns, are the last to merge with the wider party.
Does this cluster make sense?
Can we rationalize why machine learning has isolated this cluster? If we inspect the ten MPs recording the fewest votes since June 8th, 2017, it does include all six.
Nonetheless, non-voting will not be the only influencing factor. A small minority of MPs voting the opposite way to the overwhelming majority will influence the “distant cluster”.
Cook’s Distance visualizes these influential outliers. It shows the voting of three MPs, all on the European Union Withdrawal Bill readings, to be particular outliers. All three MPs are in the “cluster of six”.
So, in summary, we established that the data is suitable for hierarchical clustering and selected the clustering method that best fits the data. We identified a “cluster of six” MPs who are the last to combine with the rest of the party. And, by inspecting the non-votes and most influential outliers, we can rationalize why unsupervised machine learning merged these MPs last.
|purrr||map_df; pmap; map_lgl; transpose; safely|
|dplyr||mutate; select; if_else; left_join; everything; summarise; group_by; arrange|
|lubridate||month; day; year|
|ggplot2||geom_col; geom_text; ggtitle; coord_flip; geom_text_repel; geom_jitter|
|dendextend||dendlist; color_branches; assign_values_to_leaves_nodePar|
Citations / Attributions
R Development Core Team (2008). R: A language and environment for
statistical computing. R Foundation for Statistical Computing,
Vienna, Austria. ISBN 3-900051-07-0, URL http://www.R-project.org.
Tal Galili (2015). dendextend: an R package for visualizing, adjusting, and comparing trees of hierarchical clustering. Bioinformatics <doi:10.1093/bioinformratics/btv428>
Odell E (2017). hansard: Provides Easy Downloading Capabilities for the UK Parliament API. doi: 10.5281/zenodo.591264, R package version 0.5.5, https://cran.r-project.org/package=hansard.
Please visit source website for post related comments.