aboutsummaryrefslogtreecommitdiff
path: root/Assignment 4/ex42.py
blob: ad22fafde4520f8f05af66c5a507ab826fbbbc8d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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()