-
Notifications
You must be signed in to change notification settings - Fork 258
adding the variance threshold #2155
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -85,10 +85,12 @@ def __init__( | |||||
| drop_if_constant=False, | ||||||
| drop_if_unique=False, | ||||||
| drop_null_fraction=1.0, | ||||||
| threshold=0.0, | ||||||
|
Member
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.
Suggested change
it's better to be explicit here the parameter should be renamed everywhere |
||||||
| ): | ||||||
| self.drop_if_constant = drop_if_constant | ||||||
| self.drop_if_unique = drop_if_unique | ||||||
| self.drop_null_fraction = drop_null_fraction | ||||||
| self.threshold = threshold | ||||||
|
|
||||||
| def _check_params(self): | ||||||
| if not isinstance(self.drop_if_constant, bool): | ||||||
|
|
@@ -127,8 +129,19 @@ def _drop_if_too_many_nulls(self, column): | |||||
|
|
||||||
| def _drop_if_constant(self, column): | ||||||
| if self.drop_if_constant: | ||||||
| if (sbd.n_unique(column) == 1) and (self._null_count == 0): | ||||||
| if sbd.is_numeric(column) == 1 and ( | ||||||
|
Member
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_numeric returns false if the column has dtype bool
Suggested change
also there is no need to check that it's == 1 |
||||||
| self._null_count == 0 | ||||||
| ): # if numeric or boolean | ||||||
| if ( | ||||||
| sbd.std(column) ** 2 <= self.threshold | ||||||
| ): # check if passes the threshold | ||||||
| return True | ||||||
| else: | ||||||
| return False | ||||||
| elif (sbd.n_unique(column) == 1) and (self._null_count == 0): | ||||||
|
Member
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. the condition can be simplified a bit by moving the _null_count clause outside if self.drop_if_constant and self._null_count == 0:
...
if sbd.is_numeric(column) or sbd.is_bool(column):
...
elif sbd.n_unique(column) == 1
... |
||||||
| # use the original logic to deal with the other cases | ||||||
| return True | ||||||
|
|
||||||
| return False | ||||||
|
|
||||||
| def _drop_if_unique(self, column): | ||||||
|
|
||||||
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.
This entry should be updated slightly. Something like:
DropUninformative now has the
variance_thresholdparameter, which allows to drop numeric and boolean columns whose variance is lower than the given threshold. The default behavior is unchanged.