How to use the mleap.sklearn.preprocessing.data.StringMap function in mleap

To help you get started, we’ve selected a few mleap examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github combust / mleap / python / mleap / sklearn / preprocessing / tests.py View on Github external
def string_map_deserializer_test(self):

        df = pd.DataFrame(['test_one', 'test_two', 'test_one', 'test_one', 'test_two'], columns=['a'])
        string_map = StringMap(input_features=['a'], output_features=['a_mapped'], labels={"test_one":1.0, "test_two": 0.0})
        string_map.serialize_to_bundle(self.tmp_dir, string_map.name)

        # Now deserialize it back
        node_name = "{}.node".format(string_map.name)
        string_map_tf = StringMap()
        string_map_tf = string_map_tf.deserialize_from_bundle(self.tmp_dir, node_name)

        # Transform some sample data
        res_a = string_map.fit_transform(df)
        res_b = string_map_tf.fit_transform(df)

        self.assertEqual(res_a[0], res_b[0])
        self.assertEqual(res_a[1], res_b[1])
        self.assertEqual(res_a[2], res_b[2])
        self.assertEqual(res_a[3], res_b[3])
        self.assertEqual(res_a[4], res_b[4])
        self.assertEqual(string_map.name, string_map_tf.name)
        self.assertEqual(string_map.op, string_map_tf.op)
        self.assertEqual(string_map.labels, string_map_tf.labels)
github combust / mleap / python / mleap / sklearn / preprocessing / tests.py View on Github external
def string_map_test(self):

        df = pd.DataFrame(['test_one', 'test_two', 'test_one', 'test_one', 'test_two'], columns=['a'])
        string_map_tf = StringMap(input_features=['a'], output_features=['a_mapped'], labels={"test_one":1.0, "test_two": 0.0})

        Xres = string_map_tf.fit_transform(df)
        self.assertEqual(1.0, Xres[0])
        self.assertEqual(0.0, Xres[1])
        self.assertEqual(1.0, Xres[2])
        self.assertEqual(1.0, Xres[3])
        self.assertEqual(0.0, Xres[4])

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

        expected_model = {
            "op": "string_map",
            "attributes": {
                "labels": {
                    "type": "list",
                    "string": ["test_one", "test_two"]
github combust / mleap / python / mleap / sklearn / preprocessing / tests.py View on Github external
def string_map_deserializer_test(self):

        df = pd.DataFrame(['test_one', 'test_two', 'test_one', 'test_one', 'test_two'], columns=['a'])
        string_map = StringMap(input_features=['a'], output_features=['a_mapped'], labels={"test_one":1.0, "test_two": 0.0})
        string_map.serialize_to_bundle(self.tmp_dir, string_map.name)

        # Now deserialize it back
        node_name = "{}.node".format(string_map.name)
        string_map_tf = StringMap()
        string_map_tf = string_map_tf.deserialize_from_bundle(self.tmp_dir, node_name)

        # Transform some sample data
        res_a = string_map.fit_transform(df)
        res_b = string_map_tf.fit_transform(df)

        self.assertEqual(res_a[0], res_b[0])
        self.assertEqual(res_a[1], res_b[1])
        self.assertEqual(res_a[2], res_b[2])
        self.assertEqual(res_a[3], res_b[3])
        self.assertEqual(res_a[4], res_b[4])