Lan Zagar avatar Lan Zagar committed ecfb237

Binary classification data generation added.

Comments (0)

Files changed (1)


-from numpy import dot, zeros, column_stack, vstack, concatenate, random as rnd
+from numpy import (dot, zeros, column_stack, vstack, concatenate,
+                   exp, sqrt, random as rnd)
 import Orange
+def sigmoid(x):
+    return 1. / (1 + exp(-x))
 def to_table(X, y=None):
     n, m = X.shape
     features = [Orange.feature.Continuous('f%i' % i) for i in range(m)]
     if y is None:
         return, False), X)
+    if set(y) == {0, 1}:
+        cls = Orange.feature.Discrete('class', values=['0', '1'])
-        return
-  , Orange.feature.Continuous('class')),
-            column_stack((X, y)))
+        cls = Orange.feature.Continuous('class')
+    return, cls),
+                             column_stack((X, y)))
 class Generator(object):
     def generate_matrix(self, **kwargs):
             ins[task] = t
         return data
+class Group_binary(Group):
+    def __init__(self, mu=0, sigma=1, **kwargs):
+        Group.__init__(self, **kwargs)
+        self.intercepts = (self.intercepts - 100 + mu) / 40.
+        self.weights *= 4 * sigma / sqrt(sum(self.factors) * self.pergroup)
+    def generate_matrix(self, pertask=50, seed=None):
+        X, y = Group.generate_matrix(self, pertask, seed)
+        y = (rnd.rand(len(y)) < sigmoid(y)).astype(int)
+        return X, y
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.