示例#1
0
    def test_FeatureReducer(self):
        df = self.test_df
        target = 'gap expt'
        fr = FeatureReducer()

        # ultra-basic case: are we reducing at least 1 feature?
        df = fr.fit_transform(df, target)
        self.assertTrue(df.shape[1] < self.test_df.shape[1])

        # ensure metadata is being written correctly
        self.assertTrue(target not in fr.retained_features)
        self.assertTrue(len(list(fr.removed_features.keys())) == 2)

        # ensure other combinations of feature reducers are working
        fr = FeatureReducer(reducers=('corr', 'rebate'), n_rebate_features=40)
        df = fr.fit_transform(self.test_df, target)
        self.assertEqual(df.shape[1], 41)  # 40 features + target
        self.assertTrue(target in df.columns)

        # ensure the same thing works when fraction is used
        fr = FeatureReducer(reducers=('rebate', ), n_rebate_features=0.2)
        df = fr.fit_transform(self.test_df, target)
        self.assertEqual(df.shape[1], 83 + 1)

        # test transferability
        df2 = self.test_df
        df2 = fr.transform(df2, target)
        self.assertListEqual(df.columns.tolist(), df2.columns.tolist())
示例#2
0
    def test_FeatureReducer_transferability(self):
        # ensure the same thing works when fraction is used
        fr = FeatureReducer(reducers=("rebate", ), n_rebate_features=0.2)
        df = fr.fit_transform(self.test_df, self.target)
        self.assertEqual(df.shape[1], 83 + 1)

        # test transferability
        df2 = deepcopy(self.test_df)
        df2 = fr.transform(df2, self.target)
        self.assertListEqual(df.columns.tolist(), df2.columns.tolist())