Skip to content

Commit 8fcb215

Browse files
committed
Make python 2 compatible by setting smoothing in target encode to float
1 parent d511b0a commit 8fcb215

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

category_encoders/target_encoder.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,11 +215,11 @@ def target_encode(self, X_in, y, mapping=None, cols=None, impute_missing=True,
215215

216216
X[str(col) + '_tmp'] = np.nan
217217
for val in tmp:
218-
tmp[val]['mean'] = tmp[val]['sum']/tmp[val]['count']
219218
if tmp[val]['count'] == 1:
220219
X.loc[X[col] == val, str(col) + '_tmp'] = self._mean
221220
else:
222-
smoothing = smoothing_in
221+
# Make smoothing a float so that python 2 does not treat as integer division
222+
smoothing = float(smoothing_in)
223223
smoothing = 1 / (1 + np.exp(-(tmp[val]["count"] - min_samples_leaf) / smoothing))
224224
cust_smoothing = prior * (1 - smoothing) + tmp[val]['mean'] * smoothing
225225
X.loc[X[col] == val, str(col) + '_tmp'] = cust_smoothing

0 commit comments

Comments
 (0)