How to use the mleap.sklearn.preprocessing.data.LabelEncoder 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 one_hot_encoder_deserializer_test(self):

        labels = ['a', 'b', 'c']

        le = LabelEncoder(input_features=['label_feature'],
                          output_features='label_feature_le_encoded')

        oh_data = le.fit_transform(labels).reshape(3, 1)

        one_hot_encoder_tf = OneHotEncoder(sparse=False)
        one_hot_encoder_tf.mlinit(prior_tf = le,
                                  output_features='{}_one_hot_encoded'.format(le.output_features))
        one_hot_encoder_tf.fit(oh_data)

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

        # Deserialize the OneHotEncoder
        node_name = "{}.node".format(one_hot_encoder_tf.name)
        one_hot_encoder_tf_ds = OneHotEncoder()
        one_hot_encoder_tf_ds.deserialize_from_bundle(self.tmp_dir, node_name)
github combust / mleap / python / mleap / sklearn / preprocessing / tests.py View on Github external
le = LabelEncoder(input_features=['label_feature'],
                          output_features='label_feature_le_encoded')

        le.fit(labels)

        self.assertEqual(labels, le.classes_.tolist())

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

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

        # Deserialize the LabelEncoder
        node_name = "{}.node".format(le.name)
        label_encoder_tf = LabelEncoder()
        label_encoder_tf.deserialize_from_bundle(self.tmp_dir, node_name)

        # Transform some sample data
        res_a = le.transform(labels)
        res_b = label_encoder_tf.transform(labels)
        print("le.output_features: {}".format(le.output_features))
        print("label_encoder_tf.output_features: {}".format(label_encoder_tf.output_features))
        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(le.input_features, label_encoder_tf.input_features)
        self.assertEqual(le.output_features, label_encoder_tf.output_features[0])
github combust / mleap / python / mleap / sklearn / preprocessing / tests.py View on Github external
def label_encoder_deserializer_test(self):

        labels = ['a', 'b', 'c']

        le = LabelEncoder(input_features=['label_feature'],
                          output_features='label_feature_le_encoded')

        le.fit(labels)

        self.assertEqual(labels, le.classes_.tolist())

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

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

        # Deserialize the LabelEncoder
        node_name = "{}.node".format(le.name)
        label_encoder_tf = LabelEncoder()
        label_encoder_tf.deserialize_from_bundle(self.tmp_dir, node_name)
github combust / mleap / python / mleap / sklearn / preprocessing / tests.py View on Github external
def label_encoder_test(self):

        labels = ['a', 'b', 'c']

        le = LabelEncoder(input_features=['label_feature'],
                  output_features='label_feature_le_encoded')

        le.fit(labels)

        self.assertEqual(labels, le.classes_.tolist())

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

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

        self.assertEqual(le.op, model['op'])
        self.assertEqual('nullable_input', model['attributes'].keys()[0])
        self.assertEqual('labels', model['attributes'].keys()[1])
github combust / mleap / python / mleap / sklearn / preprocessing / tests.py View on Github external
def one_hot_encoder_serializer_test(self):

        labels = ['a', 'b', 'c']

        le = LabelEncoder(input_features=['label_feature'],
                          output_features='label_feature_le_encoded')

        oh_data = le.fit_transform(labels).reshape(3, 1)

        one_hot_encoder_tf = OneHotEncoder(sparse=False)
        one_hot_encoder_tf.mlinit(prior_tf=le,
                                  output_features='{}_one_hot_encoded'.format(le.output_features))
        one_hot_encoder_tf.fit(oh_data)

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

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

        self.assertEqual(one_hot_encoder_tf.op, model['op'])