-
-
Notifications
You must be signed in to change notification settings - Fork 258
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
Fix simple impute #788
Open
abduhbm
wants to merge
5
commits into
dask:main
Choose a base branch
from
abduhbm:fix-simple-impute
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Fix simple impute #788
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
a8c228c
Fix `median` and `most_frequent` strategies in `SimpleImpute._fit_frame`
abduhbm 3c2831c
Lint
abduhbm a92bfd5
compat
abduhbm ffaeb80
Fix compat for finding smallest most_frequent
abduhbm b15ef37
Merge branch 'main' of github.com:dask/dask-ml into fix-simple-impute
abduhbm 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -70,12 +70,18 @@ def _fit_frame(self, X): | |
if self.strategy == "mean": | ||
avg = X.mean(axis=0).values | ||
elif self.strategy == "median": | ||
avg = X.quantile().values | ||
avg = [np.median(X[col].dropna()) for col in X.columns] | ||
elif self.strategy == "constant": | ||
avg = np.full(len(X.columns), self.fill_value) | ||
else: | ||
avg = [X[col].value_counts().nlargest(1).index for col in X.columns] | ||
avg = np.concatenate(*dask.compute(avg)) | ||
avg = [] | ||
for col in X.columns: | ||
val_counts = X[col].value_counts().reset_index() | ||
if isinstance(X, dd.DataFrame): | ||
x = val_counts.to_dask_array(lengths=True) | ||
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. Do we need lengths here? This also triggers a computation. 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. This is needed to compute chunk sizes ... any suggestion on how to avoid it? Thanks, |
||
else: | ||
x = val_counts.values | ||
avg.append(x[(x[:, 1] == x[:, 1][0])][:, 0].min()) | ||
|
||
self.statistics_ = pd.Series(dask.compute(avg)[0], index=X.columns) | ||
|
||
|
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.
I believe this will eagerly compute the values, thanks to
np.median
. Since that's done in a list comprehension, we'd end up executing the graph forX
once per column. We want to delay computation till the end.I also think this will end up pulling all the data for a column into a single ndarray, to do the median, which we also want to avoid.
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.
How about using
delayed
here?