We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 95b9140 commit 394b431Copy full SHA for 394b431
tests/test_leave_one_out.py
@@ -116,3 +116,23 @@ def test_HandleUnknownValue_HaveUnknownInTest_ExpectMean(self):
116
obtained = ce_leave.transform(test, test_target)
117
118
self.assertEqual([1.0, .6], list(obtained['color']))
119
+
120
+ def test_leave_one_out_categorical(self):
121
+ """
122
+ test that if the input is a pd.Categorical the output is the same as for string columns
123
+ :return:
124
125
+ df = pd.DataFrame({
126
+ 'color_str': ["a", "a", "a", "b", "b", "b"],
127
+ 'color_num_cat': pd.Categorical([1.0, 1.0, 1.0, 2.0, 2.0, 2.0]),
128
+ 'color_str_cat': pd.Categorical(["a", "a", "a", "b", "b", "b"]),
129
+ 'outcome': [1, 0, 0, 1, 0, 1]})
130
131
+ X = df.drop('outcome', axis=1)
132
+ y = df["outcome"]
133
134
+ ce_leave = encoders.LeaveOneOutEncoder()
135
+ obtained = ce_leave.fit_transform(X, y)
136
137
+ for col in obtained.columns:
138
+ self.assertEqual([0.0, 0.5, 0.5, 0.5, 1.0, 0.5], list(obtained[col]))
0 commit comments