diff options
Diffstat (limited to 'Assignment 4/ex41.py')
-rw-r--r-- | Assignment 4/ex41.py | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/Assignment 4/ex41.py b/Assignment 4/ex41.py index 5ae66db..c3a9fc5 100644 --- a/Assignment 4/ex41.py +++ b/Assignment 4/ex41.py @@ -11,19 +11,27 @@ import sys sys.path.insert(0, './packages') import numpy as np -from scipy import io as sciio +import scipy.io as sciio from sklearn import cluster from clusterPlot import clusterPlot from clusterVal import clusterVal import matplotlib.pyplot as plt # 4.1.1 -n = 1 +plt.figure(figsize=(16,10)) +for n in range(1,5): + synth = sciio.loadmat('./data/synth' + str(n) + '.mat') + X = synth['X'] + y = synth['y'] + centroid, label, inertia = cluster.k_means(X, 4) + plt.subplot(2, 2, n) + clusterPlot(X, label, centroid, y) +plt.show() + +n = 1 synth = sciio.loadmat('./data/synth' + str(n) + '.mat') X = synth['X'] y = synth['y'] -centroid, label, inertia = cluster.k_means(X, 4) -clusterPlot(X, label, centroid, y) # 4.1.2 entropies, purities, rands, jaccards = [], [], [], [] @@ -35,8 +43,6 @@ for i in range(1, 11): rands.append(rand) jaccards.append(jaccard) -print(entropies, purities, rands, jaccards) - x = np.arange(1,11) plt.figure(figsize=(8,8)) plt.subplot(2,2,1) @@ -56,8 +62,8 @@ plt.show() # 4.1.3 faces = sciio.loadmat('./data/wildfaces.mat') X = faces['X'] -k = 0 -centroid, label, inertia = cluster.k_means(X, 10) +k = 10 +centroid, label, inertia = cluster.k_means(X, k) n = 10 plt.figure(figsize=(n*2,4)) @@ -73,7 +79,7 @@ plt.show() # 4.1.4 digits = sciio.loadmat('./data/digits.mat') X = digits['X'] -k = 20 +k = 10 plt.figure(figsize=(6,4)) for k in range(0,24): |