-
Notifications
You must be signed in to change notification settings - Fork 325
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Set HyperTransformer configuration manually #995
Merged
pvk-developer
merged 7 commits into
master
from
issue-982-set-hypertransformer-config-manually
Sep 7, 2022
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
0d475f0
Change from detect to set config
pvk-developer 5c7e6ea
Add tests constraints/base
pvk-developer 95c0676
Fix unit tests
pvk-developer 428ae44
fix data empty only for fit columns
pvk-developer 4dfad77
Fix lint
pvk-developer 24e4314
rename hp to ht
pvk-developer 1c0f81e
Remove unused transform / reverse transform
pvk-developer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -389,7 +389,7 @@ def _build_fields_metadata(self, data): | |
|
||
return fields_metadata | ||
|
||
def _get_transformers(self, dtypes): | ||
def _get_hypertransformer_config(self, dtypes): | ||
"""Create the transformer instances needed to process the given dtypes. | ||
|
||
Args: | ||
|
@@ -398,15 +398,19 @@ def _get_transformers(self, dtypes): | |
|
||
Returns: | ||
dict: | ||
mapping of field names and transformer instances. | ||
A dict containing the ``sdtypes`` and ``transformers`` config for the | ||
``rdt.HyperTransformer``. | ||
""" | ||
transformers = dict() | ||
sdtypes = dict() | ||
for name, dtype in dtypes.items(): | ||
dtype = np.dtype(dtype).kind | ||
field_metadata = self._fields_metadata.get(name, {}) | ||
transformer_template = field_metadata.get( | ||
'transformer', self._dtype_transformers[np.dtype(dtype).kind]) | ||
'transformer', self._dtype_transformers[dtype]) | ||
|
||
if transformer_template is None: | ||
sdtypes[name] = self._DTYPES_TO_TYPES.get(dtype, {}).get('type', 'categorical') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a unit test that checks this case (when |
||
transformers[name] = None | ||
continue | ||
|
||
|
@@ -422,8 +426,9 @@ def _get_transformers(self, dtypes): | |
LOGGER.debug('Loading transformer %s for field %s', | ||
transformer.__class__.__name__, name) | ||
transformers[name] = transformer | ||
sdtypes[name] = self._DTYPES_TO_TYPES.get(dtype, {}).get('type', 'categorical') | ||
|
||
return transformers | ||
return {'sdtypes': sdtypes, 'transformers': transformers} | ||
|
||
def _fit_constraints(self, data): | ||
errors = [] | ||
|
@@ -510,20 +515,20 @@ def _fit_hyper_transformer(self, data, extra_columns): | |
else: | ||
dtypes[column] = dtype_kind | ||
|
||
transformers_dict = self._get_transformers(dtypes) | ||
ht_config = self._get_hypertransformer_config(dtypes) | ||
for column in numerical_extras: | ||
transformers_dict[column] = rdt.transformers.FloatFormatter( | ||
dtypes[column] = 'numerical' | ||
ht_config['sdtypes'][column] = 'numerical' | ||
ht_config['transformers'][column] = rdt.transformers.FloatFormatter( | ||
missing_value_replacement='mean', | ||
model_missing_values=True, | ||
) | ||
|
||
self._hyper_transformer = rdt.HyperTransformer() | ||
self._hyper_transformer.detect_initial_config(data) | ||
if transformers_dict: | ||
self._hyper_transformer.update_transformers(transformers_dict) | ||
|
||
if not data.empty: | ||
self._hyper_transformer.fit(data) | ||
self._hyper_transformer.set_config(ht_config) | ||
fit_columns = list(dtypes) | ||
if not data[fit_columns].empty: | ||
self._hyper_transformer.fit(data[fit_columns]) | ||
|
||
@staticmethod | ||
def _get_key_subtype(field_meta): | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does this take the metadata into account at all? I'm trying to figure out why it wasn't before and what has changed now. For example in the
student_placements
demo it wasn't making theduration
columncategorical
even though the metadata said it wasThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Old code was reading properly the
dtype
but was printing the wrong config which leaded to confusions as thetransformers
were updated after thedetect
. Now bothsdtypes
andtransformers
are being set corresponding to thedtype
from themetadata
with theset_config
method.