Skip to content

Commit 394b431

Browse files
added test for issue 353
1 parent 95b9140 commit 394b431

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

tests/test_leave_one_out.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,3 +116,23 @@ def test_HandleUnknownValue_HaveUnknownInTest_ExpectMean(self):
116116
obtained = ce_leave.transform(test, test_target)
117117

118118
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

Comments
 (0)