diff python/ml.py @ 805:180b6b0231c0

added saving/loading points of interests
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Thu, 09 Jun 2016 15:36:21 -0400
parents 1158a6e2d28e
children 52aa03260f03
line wrap: on
line diff
--- a/python/ml.py	Tue May 31 17:07:23 2016 -0400
+++ b/python/ml.py	Thu Jun 09 15:36:21 2016 -0400
@@ -209,16 +209,16 @@
     return clusterSizes
 
 # Gaussian Mixture Models
-def plotGMMClusters(model, dataset = None, fig = None, colors = utils.colors, nPixelsPerUnit = 1., alpha = 0.3):
+def plotGMMClusters(model, dataset = None, fig = None, colors = utils.colors, nUnitsPerPixel = 1., alpha = 0.3):
     '''plot the ellipse corresponding to the Gaussians
     and the predicted classes of the instances in the dataset'''
     if fig is None:
         fig = plt.figure()
     labels = model.predict(dataset)
-    tmpDataset = nPixelsPerUnit*dataset
+    tmpDataset = dataset/nUnitsPerPixel
     for i in xrange(model.n_components):
-        mean = nPixelsPerUnit*model.means_[i]
-        covariance = nPixelsPerUnit*model.covars_[i]
+        mean = model.means_[i]/nUnitsPerPixel
+        covariance = model.covars_[i]/nUnitsPerPixel
         if dataset is not None:
             plt.scatter(tmpDataset[labels == i, 0], tmpDataset[labels == i, 1], .8, color=colors[i])
         plt.annotate(str(i), xy=(mean[0]+1, mean[1]+1))
@@ -232,3 +232,4 @@
         ell.set_clip_box(fig.bbox)
         ell.set_alpha(alpha)
         fig.axes[0].add_artist(ell)
+    return labels