示例#1
0
    def test_undersample_x2(self):
        """ Tests if undersampler samples correctly with based_minority set to 'C'."""
        sampler = Sampler(self.mvts_df, 'lab')
        minority_labels = ['NF', 'C']
        majority_labels = ['X', 'M']
        base_minority = 'C'                    # ---> base class is set to 'C'
        sampler.undersample(minority_labels=minority_labels,
                            majority_labels=majority_labels,
                            base_minority=base_minority)

        expected_populations = {'NF': 8, 'M': 8, 'X': 8, 'C': 8}     # |C|=8 in original mvts
        self.assertDictEqual(expected_populations, sampler.sampled_class_populations)
示例#2
0
    def test_undersample_x3(self):
        """ Tests if undersampler samples correctly with based_minority set to 'C'."""
        sampler = Sampler(self.mvts_df, 'lab')
        minority_labels = ['NF', 'C']
        majority_labels = ['X', 'M']
        base_minority = 'C'                    # ---> base class is set to 'C'
        sampler.undersample(minority_labels=minority_labels,
                            majority_labels=majority_labels,
                            base_minority=base_minority)

        expected_ratios = {'NF': 0.25, 'M': 0.25, 'X': 0.25, 'C': 0.25}  # 0.25 = 8 / (4 X 8)
        self.assertDictEqual(expected_ratios, sampler.sampled_class_ratios)
示例#3
0
    def test_undersample_x1(self):
        """ Tests if undersampler samples correctly with based_minority set to 'NF'."""
        sampler = Sampler(self.mvts_df, 'lab')
        minority_labels = ['NF', 'C']
        majority_labels = ['X', 'M']
        base_minority = 'NF'                    # ---> base class is set to 'NF'
        sampler.undersample(minority_labels=minority_labels,
                            majority_labels=majority_labels,
                            base_minority=base_minority)

        expected_populations = {'NF': 36, 'M': 36, 'X': 36, 'C': 36}     # |NF|=36 in original mvts
        expected_ratios = {'NF': 0.25, 'M': 0.25, 'X': 0.25, 'C': 0.25}  # 0.25 = 36 / (4 X 36)

        self.assertDictEqual(expected_populations, sampler.sampled_class_populations)
        self.assertDictEqual(expected_ratios, sampler.sampled_class_ratios)