Skip to content

Commit 2dcc9b4

Browse files
committed
Move cast from loop to constructor
1 parent 8fcb215 commit 2dcc9b4

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

category_encoders/target_encoder.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@ def __init__(self, verbose=0, cols=None, drop_invariant=False, return_df=True, i
8080
self.verbose = verbose
8181
self.cols = cols
8282
self.min_samples_leaf = min_samples_leaf
83-
self.smoothing = smoothing
83+
# Make smoothing a float so that python 2 does not treat as integer division
84+
self.smoothing = float(smoothing)
8485
self._dim = None
8586
self.mapping = None
8687
self.impute_missing = impute_missing
@@ -218,8 +219,7 @@ def target_encode(self, X_in, y, mapping=None, cols=None, impute_missing=True,
218219
if tmp[val]['count'] == 1:
219220
X.loc[X[col] == val, str(col) + '_tmp'] = self._mean
220221
else:
221-
# Make smoothing a float so that python 2 does not treat as integer division
222-
smoothing = float(smoothing_in)
222+
smoothing = 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)