예제 #1
0
    def test_target_encoder_set_attributes_from_dict(self):

        encoder = TargetEncoder()

        data = {
            "weight": 0.0,
            "_global_mean": 0.5,
            "_mapping": {
                "variable": {
                    "negative": 0.333333,
                    "neutral": 0.50000,
                    "positive": 0.666667
                }
            }
        }

        encoder.set_attributes_from_dict(data)

        expected = pd.Series(data=[0.333333, 0.50000, 0.666667],
                             index=["negative", "neutral", "positive"])
        expected.index.name = "variable"

        actual = encoder._mapping["variable"]

        pd.testing.assert_series_equal(actual, expected)
예제 #2
0
    def test_target_encoder_set_attributes_from_dict_unfitted(self, attribute):
        encoder = TargetEncoder()

        data = {"weight": 1.0}
        encoder.set_attributes_from_dict(data)

        if attribute == "weight":
            actual = encoder.weight
            expected = 1.0

            assert expected == actual
        elif attribute == "mapping":
            actual = encoder._mapping
            expected = {}

            assert expected == actual