Lan Zagar avatar Lan Zagar committed a258dff

Add two helper functions.

Comments (0)

Files changed (1)


 from __future__ import absolute_import
+from collections import defaultdict
 from pkg_resources import resource_filename
 import Orange
 from . import mtfeat
     return {ind:, ind)
             for ind in sorted(set(task_indices))}
+def get_groups(domain, feat_att=None):
+    if feat_att is None and domain.features and domain.features[0].attributes:
+        feat_att = domain.features[0].attributes.keys()[0]
+    groups = defaultdict(list)
+    for i, f in enumerate(domain.features):
+        groups[f.attributes[feat_att]].append(i)
+    return groups.values()
+def join(datas):
+    """Join data sets with same domains into a single multi-task data set."""
+    dom = datas[0].domain
+    for d in datas[1:]:
+        if not all(f1 == f2 for f1, f2 in zip(dom, d.domain)):
+            print d
+            raise Exception('Different domains')
+    task = Orange.feature.Continuous('task')
+    mid = Orange.feature.Descriptor.new_meta_id()
+    dom.add_meta(mid, task)
+    data =
+    for i, d in enumerate(datas):
+        for ins in d:
+            data.append(ins)
+            data[-1]['task'] = float(i)
+    return data
 class MultiTaskLearner(Orange.classification.Learner):
     """Learn a model for each task independently."""
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
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.