From d8ac227e7e587669843598989bdeec41654a3fa7 Mon Sep 17 00:00:00 2001 From: Camil Staps Date: Fri, 27 Nov 2015 14:45:18 +0100 Subject: Finish assignment 4 --- Assignment 4/ex42.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 Assignment 4/ex42.py (limited to 'Assignment 4/ex42.py') diff --git a/Assignment 4/ex42.py b/Assignment 4/ex42.py new file mode 100644 index 0000000..ad22faf --- /dev/null +++ b/Assignment 4/ex42.py @@ -0,0 +1,34 @@ +# -*- coding: utf-8 -*- +""" +Created on Fri Oct 23 14:45:21 2015 + +@author: Camil Staps, s4498062 + +This is Python 2 code. +""" + +import sys +sys.path.insert(0, './packages') + +import scipy.io as sciio +import scipy.cluster.hierarchy as hier +from clusterPlot import clusterPlot +import matplotlib.pyplot as plt + +# 4.2.1 +for method in ['single', 'complete', 'average']: + fig = plt.figure(figsize=(16,18)) + for n in range(1,5): + synth = sciio.loadmat('./data/synth' + str(n) + '.mat') + X = synth['X'] + y = synth['y'] + + Z = hier.linkage(X, method=method, metric='euclidean') + cls = hier.fcluster(Z, criterion='maxclust', t=4) + + plt.subplot(4, 2, n * 2 - 1) + clusterPlot(X, cls, y=y) + plt.subplot(4, 2, n * 2) + hier.dendrogram(Z) + plt.tick_params(axis='x', which='both', bottom='off', top='off', labelbottom='off') + plt.show() -- cgit v1.2.3