Commits

Miha Stajdohar committed e1e653d

Find representative models.

Comments (0)

Files changed (1)

orangecontrib/modelmaps/modelmap.py

 .. autofunction:: get_feature_subsets
 
 """
-import bz2, itertools, math, random, os.path, time
+import bz2, collections, itertools, math, random, os.path, time
 import cPickle as pickle
 
 import scipy.stats
 import model
 
 
-MODEL_LIST = ["", "SCATTERPLOT", "RADVIZ", "SPCA", "POLYVIZ", "TREE", "NaiveLearner", "kNNLearner", "SVM", "RF"]
+MODEL_LIST = ["", "SCATTERPLOT", "RADVIZ", "SPCA", "POLYVIZ", "TREE", "NaiveLearner", "kNNLearner", "SVMLearner", "RF"]
 
 
 def distance_mi(m1, m2):
         table = get_models_table()
         table.extend([model.get_instance(table.domain) for model in models])
         return table
+
+
+    def select_representatives(self, models, dist=distance_euclidean):
+        print models[0].type
+        smx = self.build_model_matrix(models, distance_euclidean)
+        nc, knn = 2, 1
+        while nc > 1:
+            net = model_network(smx, knn=knn)
+            nc = len(network.nx.algorithms.components.connected_components(net))
+            print "  knn: {}, components: {}".format(knn, nc)
+            knn += 1
+
+        clusters = collections.defaultdict(list)
+        for node, cluster in network.community.label_propagation(net, seed=42).iteritems():
+            clusters[cluster].append(node)
+
+        print "  representatives: {}".format(len(clusters))
+
+        representatives = []
+        for nodes in clusters.values():
+            cmatrix = smx.getitems(nodes)
+            cdsts  = zip([sum(i) for i in cmatrix], nodes)
+            cmedian = min(cdsts)[1]
+            representatives.append(models[cmedian])
+
+        return representatives
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.