Пример #1
0
        def transform_discrete(var):
            if (len(var.values) < 2 or treat == Continuize.Remove
                    or treat == Continuize.RemoveMultinomial
                    and len(var.values) > 2):
                return []
            if treat == Continuize.AsOrdinal:
                new_var = ContinuousVariable(var.name,
                                             compute_value=Identity(var),
                                             sparse=var.sparse)
                return [new_var]
            if treat == Continuize.AsNormalizedOrdinal:
                n_values = max(1, len(var.values))
                if self.zero_based:
                    return [
                        ContinuousVariable(var.name,
                                           compute_value=Normalizer(
                                               var, 0, 1 / (n_values - 1)),
                                           sparse=var.sparse)
                    ]
                else:
                    return [
                        ContinuousVariable(var.name,
                                           compute_value=Normalizer(
                                               var, (n_values - 1) / 2,
                                               2 / (n_values - 1)),
                                           sparse=var.sparse)
                    ]

            new_vars = []
            if treat == Continuize.Indicators:
                base = -1
            elif treat in (Continuize.FirstAsBase,
                           Continuize.RemoveMultinomial):
                base = 0
            else:
                base = dists[var_ptr].modus()
            ind_class = [Indicator1, Indicator][self.zero_based]
            for i, val in enumerate(var.values):
                if i == base:
                    continue
                new_var = ContinuousVariable("{}={}".format(var.name, val),
                                             compute_value=ind_class(var, i),
                                             sparse=var.sparse)
                new_vars.append(new_var)
            return new_vars
Пример #2
0
    def test_normalizer(self):
        t1 = Normalizer(self.disc1, 0, 1)
        t1a = Normalizer(self.disc1a, 0, 1)
        t2 = Normalizer(self.disc2, 0, 1)
        self.assertEqual(t1, t1)
        self.assertEqual(t1, t1a)
        self.assertNotEqual(t1, t2)

        self.assertEqual(hash(t1), hash(t1a))
        self.assertNotEqual(hash(t1), hash(t2))

        t1 = Normalizer(self.disc1, 0, 1)
        t1a = Normalizer(self.disc1a, 1, 1)
        self.assertNotEqual(t1, t1a)
        self.assertNotEqual(hash(t1), hash(t1a))

        t1 = Normalizer(self.disc1, 0, 1)
        t1a = Normalizer(self.disc1a, 0, 2)
        self.assertNotEqual(t1, t1a)
        self.assertNotEqual(hash(t1), hash(t1a))
Пример #3
0
def normalized_var(var, translate, scale):
    return Orange.data.ContinuousVariable(var.name,
                                          compute_value=Normalizer(
                                              var, translate, scale))
Пример #4
0
def normalized_var(var, translate, scale):
    new_var = Orange.data.ContinuousVariable(var.name)
    norm = Normalizer(var, translate, scale)
    new_var.compute_value = norm
    return new_var