Example #1
0
    def test_logistic_regression_cv_serializer(self):

        logistic_regression = LogisticRegressionCV(fit_intercept=True)
        logistic_regression.mlinit(input_features='a',
                                   prediction_column='e_binary')

        extract_features = ['e']
        feature_extractor = FeatureExtractor(
            input_scalars=['e'],
            output_vector='extracted_e_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='e_binary')

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

        logistic_regression.fit(self.df[['a']], Xres)

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

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

        self.assertEqual(model['op'], 'logistic_regression')
        self.assertTrue(model['attributes']['intercept']['double'] is not None)
Example #2
0
    def test_logistic_regression_cv_deserializer(self):

        logistic_regression = LogisticRegressionCV(fit_intercept=True)
        logistic_regression.mlinit(input_features='a',
                                   prediction_column='e_binary')

        extract_features = ['e']
        feature_extractor = FeatureExtractor(
            input_scalars=['e'],
            output_vector='extracted_e_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='e_binary')

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

        logistic_regression.fit(self.df[['a']], Xres)

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

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

        # Now deserialize it back
        node_name = "{}.node".format(logistic_regression.name)
        logistic_regression_tf = LogisticRegressionCV()
        logistic_regression_tf = logistic_regression_tf.deserialize_from_bundle(
            self.tmp_dir, node_name)

        res_a = logistic_regression.predict(self.df[['a']])
        res_b = logistic_regression_tf.predict(self.df[['a']])

        self.assertEqual(res_a[0], res_b[0])
        self.assertEqual(res_a[1], res_b[1])
        self.assertEqual(res_a[2], res_b[2])
Example #3
0
    def test_logistic_regression_cv_deserializer(self):

        logistic_regression = LogisticRegressionCV(fit_intercept=True)
        logistic_regression.mlinit(input_features=['a', 'b', 'c'],
                                   prediction_column=['e_binary'])

        binarizer = Binarizer(threshold=0.0)
        binarizer.mlinit(input_features=['e'], output_features=['e_binary'])

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

        logistic_regression.fit(self.df[logistic_regression.input_features],
                                Xres)

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

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

        # Now deserialize it back
        node_name = "{}.node".format(logistic_regression.name)
        logistic_regression_tf = LogisticRegressionCV()
        logistic_regression_tf = logistic_regression_tf.deserialize_from_bundle(
            self.tmp_dir, node_name)

        res_a = logistic_regression.predict(
            self.df[logistic_regression.input_features])
        res_b = logistic_regression_tf.predict(
            self.df[logistic_regression_tf.input_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])
Example #4
0
    def test_logistic_regression_cv_serializer(self):

        logistic_regression = LogisticRegressionCV(fit_intercept=True)
        logistic_regression.mlinit(input_features=['a', 'b', 'c'],
                                   prediction_column=['e_binary'])

        binarizer = Binarizer(threshold=0.0)
        binarizer.mlinit(input_features=['e'], output_features=['e_binary'])

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

        logistic_regression.fit(self.df[logistic_regression.input_features],
                                Xres)

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

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

        self.assertEqual(model['op'], 'logistic_regression')
        self.assertTrue(model['attributes']['intercept']['value'] is not None)