Repository navigation
Conversation
handle_unknown to change unknown datahandle_unknown to Imputer to keep and control unknown data
jnothman
left a comment
There was a problem hiding this comment.
I don't think that is an appropriate name.. perhaps default_value
| @@ -119,10 +119,11 @@ class Imputer(BaseEstimator, TransformerMixin): | |||
| contain missing values). | |||
| """ | |||
| def __init__(self, missing_values="NaN", strategy="mean", | |||
There was a problem hiding this comment.
Please document the new parameter above
| is_col_nan = np.all(_isnan(X), axis=0) | ||
| if np.any(is_col_nan): | ||
| nan_indexes = np.where(is_col_nan)[0] | ||
| X[:, nan_indexes] = self.default_value |
There was a problem hiding this comment.
You're modifying the input! How about we just modify the calculated statistics below?
There was a problem hiding this comment.
That's a good hint, because the data structure of the calculated statistics is simpler.
| @staticmethod | ||
| def _isnan(x): | ||
| """Check whether x is nan or not.""" | ||
| return np.isnan(x) if isinstance(x, type(np.nan)) else False |
There was a problem hiding this comment.
Why didn't np.isnan just work?
There was a problem hiding this comment.
Because by using np.isnan I got tests which failed. I guess there were some side effects. By using the statistics np.isnan works well.
| [5], | ||
| [5] | ||
| ] | ||
| inputer = Imputer() |
| inputer = Imputer() | ||
| assert_array_almost_equal(inputer.fit_transform(X), X_default) | ||
|
|
||
| X_replaced = [ |
There was a problem hiding this comment.
1 and True are the same when the output is an int or float
| ] | ||
| inputer = Imputer(default_value=False) | ||
| assert_array_almost_equal(inputer.fit_transform(X_complex), X_replaced) | ||
|
|
There was a problem hiding this comment.
Also need to check this works when a column is all -1 and missing_values=-1
handle_unknown to Imputer to keep and control unknown datadefault_value to Imputer to keep and control unknown data
|
Thanks for your feedback @jnothman . How can I fix the failed doc test in 345213719#L2868-L2888? I assumed that the added docs 2e7c4c3 solved that error. |
jnothman
left a comment
There was a problem hiding this comment.
The failure is due to the automatic __repr__ including the new param.
The file you need to update is https://github.com/scikit-learn/scikit-learn/blob/master/doc/modules/preprocessing.rst.
However, you should really be modifying the new SimpleImputer in sklearn/impute.py. Your current changes affect a deprecated class.
|
Should we take this PR back? Andreas commented on the involved issue: #10671 (comment)
What do you think @jnothman ? |
|
I'm not especially enthusiastic about this PR. I think the problem of
keeping columns aligned is a bigger one. ColumnTransformer helps for some
kinds of this problem. And yet the user will have to apprehend this problem
with either solution. Yes, I think we should close.
…On 27 February 2018 at 22:19, Darius Morawiec ***@***.***> wrote:
Should we take this PR back? Andreas commented on the involved issue: #10671
(comment)
<#10671 (comment)>
How do you like the ColumnTransformer solution? It also allows different
strategies for imputation and scaling on the categorical and numerical
features, which I think is something you usually want.
What do you think @jnothman <https://github.com/jnothman> ?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#10678 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAEz6_CL6JuwY_lUgNUVxTR2aFQsq1Whks5tY-SkgaJpZM4SQLQw>
.
|
|
Yes, I see and understand it. Thanks for your help. |
Reference Issues/PRs
Fixes #10671.
What does this implement/fix? Explain your changes.
It added a new param
handle_unknownto the Imputer to enhance the possibilities to handle unknown data, because today unknown data in matrices will be dropped.Any other comments?
It's still in progress and just a suggestion to discuss.