Example #1
0
    def setUp(self):
        self.factory = AIFactory.AIFactory(builders=[],
                                           project_name='test',
                                           log_dir='test/dir')

        metadata = MetaData()
        metadata.define_numerical_columns(
            ['feature_2', 'feature_3', 'target_1'])
        metadata.define_categorical_columns(['feature_1'])

        self.builder_A = mock.Mock(spec=Builder)
        self.builder_A.dependent_on = ['B']
        self.builder_A.builder_type = 'A'
        self.builder_A.describe = mock.Mock()
        self.builder_A.describe.return_value = {'A': 1}
        self.builder_A.build = mock.Mock()

        self.builder_B = mock.Mock(spec=Builder)
        self.builder_B.dependent_on = ['C']
        self.builder_B.builder_type = 'B'
        self.builder_B.describe = mock.Mock()
        self.builder_B.describe.return_value = {'B': 1}
        self.builder_B.build = mock.Mock()

        self.builder_C = mock.Mock(spec=Builder)
        self.builder_C.dependent_on = []
        self.builder_C.builder_type = 'C'
        self.builder_C.describe = mock.Mock()
        self.builder_C.describe.return_value = {'C': 1}
        self.builder_C.build = mock.Mock()

        self.artie = self.factory.create_AI(
            [self.builder_A, self.builder_B, self.builder_C])
Example #2
0
    def setUp(self):
        data = {
            'cat_1': ['one', 'two', 'three', 'two', 'one'],
        }

        metadata = MetaData()
        metadata.define_categorical_columns(['cat_1'])

        self.df = pd.DataFrame(data)
        self.data_model = DataModel(self.df)
        self.data_model.metadata = metadata
Example #3
0
    def setUp(self):
        data = {
            'num_1': [0, 1, 2, 3, 4, 5, 6, 7, 8, 50],
            'cat_2': [1, 0, 1, 0, 1, 1, 1, 1, 0, 1]
        }

        metadata = MetaData()
        metadata.define_numerical_columns(['num_1'])
        metadata.define_categorical_columns(['cat_2'])
        self.df = pd.DataFrame(data)
        self.data_model = DataModel(self.df)
        self.data_model.metadata = metadata
Example #4
0
    def setUp(self):
        data = {
            'categorical': [
                'cat', 'dog', 'cat', 'cat', 'dog', 'bird', 'cat', 'cat', 'dog',
                'bird', 'cat', 'dog'
            ],
            'column': [12, 45, 23, 78, 4, 34, 1, 3, 89, 0, 1, 56],
        }

        metadata = MetaData()
        metadata.define_categorical_columns(['categorical'])
        self.df = pd.DataFrame(data)
        self.data_model = DataModel(self.df)
        self.data_model.metadata = metadata
Example #5
0
class TestMetaData(unittest.TestCase):
    def setUp(self):
        self._data = {
            'numerical_1': [1, 2],
            'numerical_2': [3, 4],
            'numerical_3': [3, 4],
            'categorical_1': [7, 8],
            'categorical_2': [5, 6],
            'categorical_3': [5, 6],
            'unknown_1': [9, 10]
        }

        self._dataframe = pd.DataFrame(data=self._data)
        self.meta_data = MetaData(self._dataframe)

    def test_categorize_columns(self):
        # categorize all columns
        self.meta_data.define_categorical_columns(
            ['categorical_1', 'categorical_2'])
        self.meta_data.define_numerical_columns(['numerical_1', 'numerical_2'])
        self.meta_data.define_categorical_columns(['categorical_3'])
        self.meta_data.define_numerical_columns(['numerical_3'])

        # scramble the columns
        self.meta_data.define_categorical_columns(
            ['numerical_1', 'numerical_2'])
        self.meta_data.define_numerical_columns(
            ['categorical_1', 'categorical_2', 'unknown_1'])

        # categorize the columns again
        self.meta_data.define_categorical_columns(
            ['categorical_1', 'categorical_2'])
        self.meta_data.define_numerical_columns(['numerical_1', 'numerical_2'])
        self.meta_data.define_categorical_columns(['categorical_3'])
        self.meta_data.define_numerical_columns(['numerical_3'])
        self.meta_data.define_unknown_columns(['unknown_1'])

        self.assertListEqual(
            ['categorical_1', 'categorical_2', 'categorical_3'],
            self.meta_data.categorical_columns)
        self.assertListEqual(['numerical_1', 'numerical_2', 'numerical_3'],
                             self.meta_data.numerical_columns)
        self.assertListEqual(['unknown_1'],
                             self.meta_data.uncategorized_columns)

    def test_unknown_is_default(self):
        self.assertEqual(self.meta_data.get_column_type('categorical_2'),
                         'unknown')

    def test_to_string(self):
        self.meta_data.define_categorical_columns(
            ['categorical_1', 'categorical_2', 'categorical_3'])
        self.meta_data.define_numerical_columns(
            ['numerical_1', 'numerical_2', 'numerical_3'])

        expected_string = '\nmetadata:\ncategorical_1: ' + MetaData.CATEGORICAL_DATA_TYPE + '\ncategorical_2: ' + MetaData.CATEGORICAL_DATA_TYPE + '\ncategorical_3: ' + MetaData.CATEGORICAL_DATA_TYPE + '\nnumerical_1: ' + MetaData.NUMERICAL_DATA_TYPE + '\nnumerical_2: ' + MetaData.NUMERICAL_DATA_TYPE + '\nnumerical_3: ' + MetaData.NUMERICAL_DATA_TYPE + '\nunknown_1: ' + MetaData.UNKNOWN_DATA_TYPE
        stringified_metadata = str(self.meta_data)
        self.assertEqual(
            expected_string, stringified_metadata,
            'Metadata __str__ function does not meet expectations.')