예제 #1
0
 def test_load_table_pickle_list(self):
     table_list = ['admissions', 'patients']
     pre_store = PrepareData('test1', '../../data/demo_data/all')
     pre_store.read_tables(table_list, True)
     pre_load = PrepareData('test2', '../../data/demo_data/all')
     pre_load.load_table_pickle_list(table_list)
     self.assertEqual(pre_load.admissions['DIAGNOSIS'][2], 'SEPSIS',
                      'Not loaded multipe tables from pickle files.')
     self.assertEqual(pre_load.patients['SUBJECT_ID'][3], int(10017),
                      'Not loaded multipe tables from pickle files.')
예제 #2
0
    def test_read_tables(self):
        pre = PrepareData('test', '../../data/demo_data/all')
        table_list = ['admissions', 'patients']
        pre.read_tables(table_list)

        # Check if the two tables are loaded
        self.assertEqual(pre.admissions['DIAGNOSIS'][2], 'SEPSIS',
                         'Not read multiple tables correctly.')
        self.assertEqual(pre.patients['SUBJECT_ID'][3], int(10017),
                         'Not read multiple tables correctly.')
    def test_transform(self):
        pre = PrepareData('test', '../../data/demo_data/all')
        pre.read_tables(['prescriptions', 'admissions'])

        drug_enc = DrugEncoderV2(48, 10)
        drug_enc.fit(pre.prescriptions)
        hadm_drug_matrix, hadm_id_mapping = drug_enc.transform(
            pre.prescriptions, pre.admissions)

        self.assertTrue(
            ((hadm_drug_matrix[7, :] == [0, 1, 1, 1, 0, 1, 1, 1, 1, 0]) *
             1).sum(),
            'Error in DrugEncoder.transform(); hadm_drug_matrix wrong')

        self.assertEqual(
            hadm_drug_matrix.shape, (len(pre.admissions), 10),
            'Error in DrugEncoder.transform();  hadm_drug_matrix has wrong shape;'
        )

        self.assertEqual(len(hadm_id_mapping),
                         pre.admissions['HADM_ID'].unique().shape[0],
                         'Error in DrugEncoder.transform(); wrong shape;')

        self.assertEqual(
            drug_enc.drug_mapping, {
                'FURO40I': 0,
                'NS500': 1,
                'NS1000': 2,
                'NACLFLUSH': 3,
                'INSULIN': 4,
                'D5W250': 5,
                'VANC1F': 6,
                'VANCOBASE': 7,
                'HEPA5I': 8,
                'KCL20PM': 9
            }, 'Error in DrugEncoder.transform(); drug_mapping is wrong')