-
Notifications
You must be signed in to change notification settings - Fork 91
Add null rows check to HighlyNullDataCheck
#2222
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
Merged
Merged
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
684e419
Add highly null row data check
jeremyliweishih 49f55fb
Merge branch 'main' of github.com:alteryx/evalml into js_2220_row_dat…
jeremyliweishih 6182bad
RL
jeremyliweishih 03cb3b7
Add to API reference
jeremyliweishih faa569f
Fix doctest
jeremyliweishih 7918034
Merge branch 'main' of github.com:alteryx/evalml into js_2220_row_dat…
jeremyliweishih 752b2c4
Add to default datachecks
jeremyliweishih 1cc5bf3
Merge branch 'main' of github.com:alteryx/evalml into js_2220_row_dat…
jeremyliweishih 85a540e
Fix tests
jeremyliweishih ffa7b5a
Fix docstring
jeremyliweishih 813fa4f
Merge branch 'main' of github.com:alteryx/evalml into js_2220_row_dat…
jeremyliweishih 2a3a1ef
Fix RL
jeremyliweishih 41dc0fb
merge > 0 and 0 case
jeremyliweishih 4e8139e
Bump default to 0.75
jeremyliweishih 823ee83
Test with None and np.nan
jeremyliweishih 2bdc3a3
Merge branch 'main' of github.com:alteryx/evalml into js_2220_row_dat…
jeremyliweishih 26d12fd
Simplify highly null data check
jeremyliweishih b4e7e88
Combine row and cols check
jeremyliweishih c65a1e7
Fix default datacheck tests
jeremyliweishih 23bea89
Fix removals
jeremyliweishih 5e366f2
Add null row example to default data checks
jeremyliweishih 1aab69a
Merge branch 'main' of github.com:alteryx/evalml into js_2220_row_dat…
jeremyliweishih 8c96390
Merge branch 'main' into js_2220_row_datacheck
jeremyliweishih 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -9,45 +9,62 @@ | |
|
|
||
|
|
||
| class HighlyNullDataCheck(DataCheck): | ||
| """Checks if there are any highly-null columns in the input.""" | ||
| """Checks if there are any highly-null columns and rows in the input.""" | ||
|
|
||
| def __init__(self, pct_null_threshold=0.95): | ||
| """Checks if there are any highly-null columns in the input. | ||
| """Checks if there are any highly-null columns and rows in the input. | ||
|
|
||
| Arguments: | ||
| pct_null_threshold(float): If the percentage of NaN values in an input feature exceeds this amount, | ||
| that feature will be considered highly-null. Defaults to 0.95. | ||
| that column/row will be considered highly-null. Defaults to 0.95. | ||
|
Contributor
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. Ah, I do think it would be helpful to have a separate threshold for rows vs columns. I filed #2270 to track that separately. |
||
|
|
||
| """ | ||
| if pct_null_threshold < 0 or pct_null_threshold > 1: | ||
| raise ValueError("pct_null_threshold must be a float between 0 and 1, inclusive.") | ||
| self.pct_null_threshold = pct_null_threshold | ||
|
|
||
| def validate(self, X, y=None): | ||
| """Checks if there are any highly-null columns in the input. | ||
| """Checks if there are any highly-null columns or rows in the input. | ||
|
|
||
| Arguments: | ||
| X (ww.DataTable, pd.DataFrame, np.ndarray): Features | ||
| X (ww.DataTable, pd.DataFrame, np.ndarray): Data | ||
| y (ww.DataColumn, pd.Series, np.ndarray): Ignored. | ||
|
|
||
| Returns: | ||
| dict: dict with a DataCheckWarning if there are any highly-null columns. | ||
| dict: dict with a DataCheckWarning if there are any highly-null columns or rows. | ||
|
|
||
| Example: | ||
| >>> import pandas as pd | ||
| >>> class SeriesWrap(): | ||
| ... def __init__(self, series): | ||
| ... self.series = series | ||
| ... | ||
| ... def __eq__(self, series_2): | ||
| ... return all(self.series.eq(series_2.series)) | ||
| ... | ||
| >>> df = pd.DataFrame({ | ||
| ... 'lots_of_null': [None, None, None, None, 5], | ||
| ... 'no_null': [1, 2, 3, 4, 5] | ||
| ... }) | ||
| >>> null_check = HighlyNullDataCheck(pct_null_threshold=0.8) | ||
| >>> assert null_check.validate(df) == {"errors": [],\ | ||
| "warnings": [{"message": "Column 'lots_of_null' is 80.0% or more null",\ | ||
| "data_check_name": "HighlyNullDataCheck",\ | ||
| "level": "warning",\ | ||
| "code": "HIGHLY_NULL",\ | ||
| "details": {"column": "lots_of_null", "pct_null_rows": 0.8}}],\ | ||
| "actions": [{"code": "DROP_COL",\ | ||
| "metadata": {"column": "lots_of_null"}}]} | ||
| >>> null_check = HighlyNullDataCheck(pct_null_threshold=0.50) | ||
| >>> validation_results = null_check.validate(df) | ||
| >>> validation_results['warnings'][0]['details']['pct_null_cols'] = SeriesWrap(validation_results['warnings'][0]['details']['pct_null_cols']) | ||
| >>> highly_null_rows = SeriesWrap(pd.Series([0.5, 0.5, 0.5, 0.5])) | ||
| >>> assert validation_results== {"errors": [],\ | ||
| "warnings": [{"message": "4 out of 5 rows are more than 50.0% null",\ | ||
| "data_check_name": "HighlyNullDataCheck",\ | ||
| "level": "warning",\ | ||
| "code": "HIGHLY_NULL_ROWS",\ | ||
| "details": {"pct_null_cols": highly_null_rows}},\ | ||
| {"message": "Column 'lots_of_null' is 50.0% or more null",\ | ||
| "data_check_name": "HighlyNullDataCheck",\ | ||
| "level": "warning",\ | ||
| "code": "HIGHLY_NULL_COLS",\ | ||
| "details": {"column": "lots_of_null", "pct_null_rows": 0.8}}],\ | ||
| "actions": [{"code": "DROP_ROWS", "metadata": {"rows": [0, 1, 2, 3]}},\ | ||
| {"code": "DROP_COL",\ | ||
| "metadata": {"column": "lots_of_null"}}]} | ||
|
|
||
| """ | ||
| results = { | ||
| "warnings": [], | ||
|
|
@@ -58,25 +75,25 @@ def validate(self, X, y=None): | |
| X = infer_feature_types(X) | ||
| X = _convert_woodwork_types_wrapper(X.to_dataframe()) | ||
|
|
||
| percent_null = (X.isnull().mean()).to_dict() | ||
| highly_null_cols = [] | ||
| if self.pct_null_threshold == 0.0: | ||
| highly_null_cols = {key: value for key, value in percent_null.items() if value > 0.0} | ||
| warning_msg = "Column '{}' is more than 0% null" | ||
| results["warnings"].extend([DataCheckWarning(message=warning_msg.format(col_name), | ||
| data_check_name=self.name, | ||
| message_code=DataCheckMessageCode.HIGHLY_NULL, | ||
| details={"column": col_name, "pct_null_rows": highly_null_cols[col_name]}).to_dict() | ||
| for col_name in highly_null_cols]) | ||
| else: | ||
| highly_null_cols = {key: value for key, value in percent_null.items() if value >= self.pct_null_threshold} | ||
| warning_msg = "Column '{}' is {}% or more null" | ||
| results["warnings"].extend([DataCheckWarning(message=warning_msg.format(col_name, self.pct_null_threshold * 100), | ||
| data_check_name=self.name, | ||
| message_code=DataCheckMessageCode.HIGHLY_NULL, | ||
| details={"column": col_name, "pct_null_rows": highly_null_cols[col_name]}).to_dict() | ||
| for col_name in highly_null_cols]) | ||
| percent_null_rows = X.isnull().mean(axis=1) | ||
| highly_null_rows = percent_null_rows[percent_null_rows >= self.pct_null_threshold] | ||
| if len(highly_null_rows) > 0: | ||
| warning_msg = f"{len(highly_null_rows)} out of {len(X)} rows are more than {self.pct_null_threshold*100}% null" | ||
| results["warnings"].append(DataCheckWarning(message=warning_msg, | ||
| data_check_name=self.name, | ||
| message_code=DataCheckMessageCode.HIGHLY_NULL_ROWS, | ||
| details={"pct_null_cols": highly_null_rows}).to_dict()) | ||
|
Contributor
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. Thanks! Looks great |
||
| results["actions"].append(DataCheckAction(DataCheckActionCode.DROP_ROWS, | ||
| metadata={"rows": highly_null_rows.index.tolist()}).to_dict()) | ||
|
|
||
| percent_null_cols = (X.isnull().mean()).to_dict() | ||
| highly_null_cols = {key: value for key, value in percent_null_cols.items() if value >= self.pct_null_threshold and value != 0} | ||
| warning_msg = "Column '{}' is {}% or more null" | ||
| results["warnings"].extend([DataCheckWarning(message=warning_msg.format(col_name, self.pct_null_threshold * 100), | ||
| data_check_name=self.name, | ||
| message_code=DataCheckMessageCode.HIGHLY_NULL_COLS, | ||
| details={"column": col_name, "pct_null_rows": highly_null_cols[col_name]}).to_dict() | ||
| for col_name in highly_null_cols]) | ||
| results["actions"].extend([DataCheckAction(DataCheckActionCode.DROP_COL, | ||
| metadata={"column": col_name}).to_dict() | ||
| for col_name in highly_null_cols]) | ||
|
|
||
This file contains hidden or 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.
Uh oh!
There was an error while loading. Please reload this page.