diff options
Diffstat (limited to 'Assignment 4/ex42.py')
-rw-r--r-- | Assignment 4/ex42.py | 34 |
1 files changed, 34 insertions, 0 deletions
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() |