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
Fixed bug where PerColumnImputer cannot handle dropped columns #855
Merged
Merged
Changes from 12 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
a2ec93f
first util
angela97lin 78a5352
add util fxn init
angela97lin 3719c3a
add test
angela97lin 32cf51b
changelog
angela97lin e480ebc
Merge branch 'master' into 843_preprocessing_utils
angela97lin 428ea49
test fix for all_estimators and minimal dependencies
angela97lin 334ffe5
update since estimators have default params
angela97lin e6d7ea6
fix per col imputer
angela97lin 7dbf92b
Merge branch 'master' into 514_percol
angela97lin 5e8407b
revert from other PR
angela97lin a2ea509
changelog
angela97lin 1688b51
merge
angela97lin 7d69587
Merge branch 'master' into 514_percol
angela97lin 090bf9d
Merge remote-tracking branch 'origin' into 514_percol
angela97lin 25ec13e
update syntax
angela97lin File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
from sklearn.impute import SimpleImputer as SkImputer | ||
|
||
from evalml.pipelines.components.transformers import Transformer | ||
from evalml.pipelines.components.transformers.imputers.simple_imputer import ( | ||
SimpleImputer | ||
) | ||
|
||
|
||
class PerColumnImputer(Transformer): | ||
|
@@ -50,7 +51,7 @@ def fit(self, X, y=None): | |
strategy_dict = self.impute_strategies.get(column, dict()) | ||
strategy = strategy_dict.get('impute_strategy', self.default_impute_strategy) | ||
fill_value = strategy_dict.get('fill_value', None) | ||
self.imputers[column] = SkImputer(strategy=strategy, fill_value=fill_value) | ||
self.imputers[column] = SimpleImputer(impute_strategy=strategy, fill_value=fill_value) | ||
|
||
for column, imputer in self.imputers.items(): | ||
imputer.fit(X[[column]]) | ||
|
@@ -67,8 +68,14 @@ def transform(self, X, y=None): | |
pd.DataFrame: Transformed X | ||
""" | ||
X_t = X.copy() | ||
cols_to_drop = [] | ||
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. Can't set column to empty dataframe, so updating to check first. |
||
for column, imputer in self.imputers.items(): | ||
X_t[column] = imputer.transform(X[[column]]).astype(X.dtypes[column]) | ||
transformed = imputer.transform(X[[column]]) | ||
if transformed.empty: | ||
cols_to_drop += [column] | ||
angela97lin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
else: | ||
X_t[column] = transformed | ||
X_t = X_t.drop(cols_to_drop, axis=1) | ||
return X_t | ||
|
||
def fit_transform(self, X, y=None): | ||
|
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
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.
Rather than use
SkImputer
, I'm using ourSimpleImputer
which already handles the nan's from the previous PR :)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.
🤯 oh, great idea!! Modularity always wins 👍😁