Esempio n. 1
0
    def binarizer_deserializer_test(self):

        binarizer = Binarizer(threshold=0.0)
        binarizer.mlinit(input_features=['a'], output_features=['a_binary'])

        Xres = binarizer.fit_transform(self.df[['a']])

        # Test that the binarizer functions as expected
        self.assertEqual(
            float(len(self.df[self.df.a >= 0])) / 10.0, Xres.mean())

        binarizer.serialize_to_bundle(self.tmp_dir, binarizer.name)

        # Deserialize the Binarizer
        node_name = "{}.node".format(binarizer.name)
        binarizer_tf_ds = Binarizer()
        binarizer_tf_ds.deserialize_from_bundle(self.tmp_dir, node_name)

        # Transform some sample data
        res_a = binarizer.transform(self.df[['a']])
        res_b = binarizer_tf_ds.transform(self.df[['a']])

        self.assertEqual(res_a[0][0], res_b[0][0])
        self.assertEqual(res_a[1][0], res_b[1][0])
        self.assertEqual(res_a[2][0], res_b[2][0])
        self.assertEqual(res_a[3][0], res_b[3][0])
Esempio n. 2
0
    def binarizer_deserializer_test(self):

        extract_features = ['a']
        feature_extractor = FeatureExtractor(
            input_scalars=['a'],
            output_vector='extracted_a_output',
            output_vector_items=["{}_out".format(x) for x in extract_features])

        binarizer = Binarizer(threshold=0.0)
        binarizer.mlinit(prior_tf=feature_extractor,
                         output_features='a_binary')

        Xres = binarizer.fit_transform(self.df[['a']])

        # Test that the binarizer functions as expected
        self.assertEqual(
            float(len(self.df[self.df.a >= 0])) / 10.0, Xres.mean())

        binarizer.serialize_to_bundle(self.tmp_dir, binarizer.name)

        # Deserialize the Binarizer
        node_name = "{}.node".format(binarizer.name)
        binarizer_tf_ds = Binarizer()
        binarizer_tf_ds.deserialize_from_bundle(self.tmp_dir, node_name)

        # Transform some sample data
        res_a = binarizer.transform(self.df[['a']])
        res_b = binarizer_tf_ds.transform(self.df[['a']])

        self.assertEqual(res_a[0][0], res_b[0][0])
        self.assertEqual(res_a[1][0], res_b[1][0])
        self.assertEqual(res_a[2][0], res_b[2][0])
        self.assertEqual(res_a[3][0], res_b[3][0])
Esempio n. 3
0
    def binarizer_test(self):

        binarizer = Binarizer(threshold=0.0)
        binarizer.mlinit(input_features='a',
                         output_features='a_binary')

        Xres = binarizer.fit_transform(self.df[['a']])

        # Test that the binarizer functions as expected
        self.assertEqual(float(len(self.df[self.df.a >= 0]))/10.0, Xres.mean())

        binarizer.serialize_to_bundle(self.tmp_dir, binarizer.name)

        expected_model = {
          "op": "binarizer",
          "attributes": {
            "threshold": {
              "type": "double",
              "value": 0.0
            }
          }
        }

        # Test model.json
        with open("{}/{}.node/model.json".format(self.tmp_dir, binarizer.name)) as json_data:
            model = json.load(json_data)

        self.assertEqual(expected_model['attributes']['threshold']['value'],
                         model['attributes']['threshold']['value'])
Esempio n. 4
0
    def binarizer_test(self):

        extract_features = ['a']
        feature_extractor = FeatureExtractor(
            input_scalars=['a'],
            output_vector='extracted_a_output',
            output_vector_items=["{}_out".format(x) for x in extract_features])

        binarizer = Binarizer(threshold=0)
        binarizer.mlinit(prior_tf=feature_extractor,
                         output_features='a_binary')

        Xres = binarizer.fit_transform(self.df[['a']])

        # Test that the binarizer functions as expected
        self.assertEqual(
            float(len(self.df[self.df.a >= 0])) / 10.0, Xres.mean())

        binarizer.serialize_to_bundle(self.tmp_dir, binarizer.name)

        expected_model = {
            "op": "sklearn_binarizer",
            "attributes": {
                "threshold": {
                    "double": 0.0
                }
            }
        }

        # Test model.json
        with open("{}/{}.node/model.json".format(self.tmp_dir,
                                                 binarizer.name)) as json_data:
            model = json.load(json_data)

        self.assertEqual(expected_model['attributes']['threshold']['double'],
                         model['attributes']['threshold']['double'])
        self.assertEqual(expected_model['op'], model['op'])

        # Test node.json
        with open("{}/{}.node/node.json".format(self.tmp_dir,
                                                binarizer.name)) as json_data:
            node = json.load(json_data)

        self.assertEqual(binarizer.name, node['name'])
        self.assertEqual(binarizer.input_features,
                         node['shape']['inputs'][0]['name'])
        self.assertEqual(binarizer.output_features,
                         node['shape']['outputs'][0]['name'])