Ejemplo n.º 1
0
    def test_instantiated_fit_values(self):
        encoder = OneHotEncoder(fit_values=["0", "1", "2"])

        expected = [(1, 0, 0), (0, 1, 0), (0, 0, 1), (0, 1, 0)]

        actual = encoder.encode(["0", "1", "2", "1"])

        self.assertEqual(actual, expected)
Ejemplo n.º 2
0
    def test_error_if_unkonwn_false(self):
        encoder = OneHotEncoder(error_if_unknown=False).fit(["0", "1", "2"])

        try:
            actual = encoder.encode(["5"])
        except:
            self.fail("An exception was raised when it shouldn't have been")

        self.assertEqual(actual, [(0, 0, 0)])
Ejemplo n.º 3
0
    def test_performance_encode(self):

        encoder = OneHotEncoder(list(range(1000)), error_if_unknown=False)
        to_encode = [100, 200, 300, 400, -1] * 100000

        time = min(
            timeit.repeat(lambda: encoder.encode(to_encode),
                          repeat=50,
                          number=1))

        #was approximately 0.040
        self.assertLess(time, 1)
Ejemplo n.º 4
0
    def test_error_if_unkonwn_true(self):
        encoder = OneHotEncoder(error_if_unknown=True).fit(
            ["1", "1", "1", "0", "0"])

        with self.assertRaises(Exception):
            self.assertEqual(encoder.encode(["2"]), [(0)])
Ejemplo n.º 5
0
    def test_singular_if_binary(self):
        encoder = OneHotEncoder(singular_if_binary=True).fit(
            ["1", "1", "1", "0", "0"])

        self.assertEqual(encoder.encode(["0"]), [(0, )])
        self.assertEqual(encoder.encode(["1"]), [(1, )])