Skip to content
This repository has been archived by the owner on Jan 9, 2024. It is now read-only.

Commit

Permalink
Passed constructor arguments of smart transformers to _get_transforme…
Browse files Browse the repository at this point in the history
…r() method by default.
  • Loading branch information
alexrallen committed Nov 30, 2018
1 parent 5777789 commit bc5b44c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
11 changes: 11 additions & 0 deletions foreshadow/tests/test_transformers/test_smart.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,3 +183,14 @@ def test_preprocessor_hashencoder_no_name_collision():
# since the number of categories for each column are above 30, HashingEncoder will be used with 30 components. The transformed
# output should have in total 60 unique names.
assert len(set(output.columns)) == 60


def test_smart_encoder_more_than_30_levels_with_overwritten_cutoff():
import numpy as np
from foreshadow.transformers.smart import Encoder
from foreshadow.transformers.internals import OneHotEncoder

np.random.seed(0)
gt_30_random_data = np.random.choice(31, size=500)
smart_coder = Encoder(unique_num_cutoff=35)
assert isinstance(smart_coder.fit(gt_30_random_data), OneHotEncoder)
2 changes: 1 addition & 1 deletion foreshadow/transformers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ def fit(self, X, y=None, **kwargs):
self.transformer = _Empty()
self._set_to_empty = True
else:
self._verify_transformer(X, y, refit=True)
self._verify_transformer(X, y, refit=True, **self.kwargs)
inject = _inject_df(self.transformer, kwargs.pop("full_df", None))
return self.transformer.fit(X, y, **{**kwargs, **inject})

Expand Down

0 comments on commit bc5b44c

Please sign in to comment.