You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The imputer should have an option to add a binary indicator feature (for each possibly missing feature) that indicate whether a feature was imputed or not (0 or 1).
In applications, missingness is often informative.
Hi, if I may, I would like to work on this. If I understand it right, only in the case of axis=0, the binary indicator of size n_features is needed to indicate whether a feature was imputed. Please correct me if something else is expected here. Thanks.
@amueller Sorry for disturbing you, but since @rvraghav93 has also mentioned about this, it would be helpful if you can give some insight into what kind of approach is being expected here. Please do reply whenever it is possible. Thanks !
If I understand it right, only in the case ofaxis=0, the binary indicator of size n_features is needed to indicate whether a feature was imputed.
No. It is applicable for both axis=0 or axis=1. The axis specification is only to derive the imputed value. (i.e to specify if we want a mean along all the feature values for that particular feature or along all the features values for that particular sample)
What we want here is to generate a simple is_imputed indicator matrix which will be of shape (n_samples x n_features). The is_imputed[i, j] will be 1 if X[i, j] was missing_values before imputation or 0 otherwise.
Whether we need this matrix to be returned or to be concatenated to the original matrix should be discussed. @amueller@GaelVaroquaux
But you can start your work assuming it has to be concatenated to the original matrix without waiting for discussions as changing it to do the other way will not require much work.
Thanks for the clarification ! I had commented that before I have looked more into imputation methods. I understand now that axis is to just specify whether to impute along columns(features) or rows(samples). I have one doubt though, in transform method the returned matrix will be shape (n_samples x n_features_new) but the shape of the indicator matrix will be of shape (n_samples x n_features) right ? So how does the approach of concatenation work here ? Sorry if I am misunderstood what you meant.
but the shape of the indicator matrix will be of shape (n_samples x n_features) right ? So how does the approach of concatenation work here ? Sorry if I am misunderstood what you meant.
No. You understood it correctly! So now the returned X will have a shape of (n_samples x (2*n_features)). Whether or not this is acceptable needs to be discussed.
I.e the new X is np.hstack((X, is_imputed))
One more thing to discuss would be whether we would want to interleave the X and is_imputed instead of hstack-ing it.
+1 . I end up implementing it by myself all the time.
@giorgiop Could you elaborate your implementation please?
I think what's missing here for @maniteja123 is motivation (it was missing for me too until @rvraghav93 described the expected output more clearly): we want the estimator that is learning from the imputed data to be able to exploit the knowledge that some values come with a higher degree of error than others.
It would be nice to see this used effectively in an example. But I'm not sure what sort of data would show its utility.
Btw, is there any value in only adding indicator columns containing at least one 1, rather than redundant empty features?
For the example the census income data set (the original one with the missing values is a good one). You can see how people conviniently choose not to answer some questions ;)
The other one is some bankruptcy dataset which was quoted in a paper by Ding Simonoff on handling missing values in Decision Trees. I haven't found out the link for such a dataset. Their claim is that in the dataset the probability of a bank going bankrupt is higher when the bank chooses not to reveal data for certain questions (features).
For the second question. Assuming I understood correctly that your question is for columns with no missing data, Yes you are right that it won't add any value but if we choose to ignore such columns in the indicator matrix, I'm afraid it would make it difficult for the user to match the column in the indicator matrix with the corresponding column in the feature matrix...
The motivation is the following: imputation implicitly discards the information that certain examples (rows) had missing values originally. Therefore, before imputation, we add a column for each feature that has at least one missing a value. The additional column is 0 everywhere, except that is it 1 when the corresponding value is missing.
There is no need to double the size of the input in general. Columns should only be concatenated to features that have missing values. This avoids redundancies.
Yes you are right that it won't add any value but if we choose to ignore such columns in the indicator matrix, I'm afraid it would make it difficult for the user to match the column in the indicator matrix with the corresponding column in the feature matrix...
I don't think imputed_features_ = [1, 2, 4, 7] is cumbersome to create, or to use! Also, get_feature_names can help.
For the second question. Assuming I understood correctly that your question is for columns with no missing data, Yes you are right that it won't add any value but if we choose to ignore such columns in the indicator matrix, I'm afraid it would make it difficult for the user to match the column in the indicator matrix with the corresponding column in the feature matrix...
True. That's a case where features names #6425 would be very useful.
@jnothman I'm not entirely sure I understand the motivation for the design. You want to keep the complexity in the Imputer small?
I don't know about all the issues the previous implementation had.
As long as adding the features is easy to do and doesn't require a FeatureUnion for the inexperienced user, I'm ok with adding a class.
It seems like a simple thing but I guess it is not?
Have we made a decision on the semantics? We add indicators for features that were missing in training and optionally either error or ignore if other features are missing?
I think the natural thing would be to either have features for the ones missing in train, for all features, or for a specified subset of features. ("missing_indicators in ["none", "all", "train", indices/mask]).
We were also discussing the option of having a global "anything missing" feature.
I think part of the issue in the previous design was trying to handle all the cases in which Imputer worked, and ideally to do so without duplicating the get_mask operation. Given the surprising complexity of the code, I think modularity will make the code much easier to implement, test and maintain, for a O(mn) cost.
Otherwise, the advantage to a separate transformer is mostly that users of external imputers can use it too.
I don't mind any of those bonus features. But I can more easily conceive of their design and documentation in a separate MissingIndicator than integrated into Imputer.
And axis=1 currently means that the missing values are set to a statistic derived from non-missing values in their row. I suspect that the MissingIndicator should work the same independent of axis.
Hi, it's been long time. I was thinking of giving this a try. AFAIU, the transformer now is just the indicator mask for the missing values and can be used with any imputer. I was hoping to get clarity on the semantics of the new class.
meaning of None for ``missing_indicators"
what does this option mean for axis =1
should there be features indicating features with all missing values.
Please let me know if I misunderstood anything. Thanks !
Yeah sure, but it was a very basic implementation and I wasn't sure if I could complete it. So I thought of not raising a PR in case someone wanted to take it up. Sorry for the delay though..
Unless I've forgotten something, I think the MissingIndicator's operation should be independent of axis. I also don't see the need for a copy parameter.
We'll probably integrate this into Imputer via an option, but initially, yes, let's build it as a separate class. Please add tests, and submit a PR.
There's an easy way to know which features were included, though it's slightly different from the design you were discussing. In fact the imputer used to do this (the version that came with Anaconda 2.5). It returned a second value containing a vector of the indices of the columns that remained. The transform method still has this info; if you just change the return statement to:
return X, valid_statistics_indexes
that will do the trick. My code which uses the imputer uses that second value. I'm not sure why it was removed.
On 12 May 2017 5:44 am, "pshell1" ***@***.***> wrote:
There's an easy way to know which features were included, though it's
slightly different from the design you were discussing. In fact the imputer
used to do this (the version that came with Anaconda 2.5). It returned a
second value containing a vector of the indices of the columns that
remained. The transform method still has this info; if you just change the
return statement to:
return X, valid_statistics_indexes
that will do the trick. My code which uses the imputer uses that second
value. I'm not sure why it was removed.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#6556 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAEz63QooC-D_NReCnygfM-U1xDmG5JBks5r42UbgaJpZM4Hya_O>
.
Activity
GaelVaroquaux commentedon Mar 16, 2016
giorgiop commentedon Mar 16, 2016
+1 . I end up implementing it by myself all the time.
maniteja123 commentedon Mar 17, 2016
Hi, if I may, I would like to work on this. If I understand it right, only in the case of
axis=0, the binary indicator of sizen_featuresis needed to indicate whether a feature was imputed. Please correct me if something else is expected here. Thanks.maniteja123 commentedon Mar 29, 2016
@amueller Sorry for disturbing you, but since @rvraghav93 has also mentioned about this, it would be helpful if you can give some insight into what kind of approach is being expected here. Please do reply whenever it is possible. Thanks !
raghavrv commentedon Mar 29, 2016
No. It is applicable for both
axis=0oraxis=1. Theaxisspecification is only to derive the imputed value. (i.e to specify if we want a mean along all the feature values for that particular feature or along all the features values for that particular sample)What we want here is to generate a simple
is_imputedindicator matrix which will be of shape(n_samples x n_features). Theis_imputed[i, j]will be 1 ifX[i, j]wasmissing_valuesbefore imputation or 0 otherwise.Whether we need this matrix to be returned or to be concatenated to the original matrix should be discussed. @amueller @GaelVaroquaux
But you can start your work assuming it has to be concatenated to the original matrix without waiting for discussions as changing it to do the other way will not require much work.
EDIT: Basically the
is_imputedmask is the return value of this existing helper function.maniteja123 commentedon Mar 29, 2016
Thanks for the clarification ! I had commented that before I have looked more into imputation methods. I understand now that axis is to just specify whether to impute along columns(features) or rows(samples). I have one doubt though, in
transformmethod the returned matrix will be shape(n_samples x n_features_new)but the shape of the indicator matrix will be of shape(n_samples x n_features)right ? So how does the approach of concatenation work here ? Sorry if I am misunderstood what you meant.raghavrv commentedon Mar 29, 2016
No. You understood it correctly! So now the returned
Xwill have a shape of(n_samples x (2*n_features)). Whether or not this is acceptable needs to be discussed.I.e the new X is
np.hstack((X, is_imputed))One more thing to discuss would be whether we would want to interleave the
Xandis_imputedinstead ofhstack-ing it.@giorgiop Could you elaborate your implementation please?
jnothman commentedon Mar 30, 2016
I think what's missing here for @maniteja123 is motivation (it was missing for me too until @rvraghav93 described the expected output more clearly): we want the estimator that is learning from the imputed data to be able to exploit the knowledge that some values come with a higher degree of error than others.
It would be nice to see this used effectively in an example. But I'm not sure what sort of data would show its utility.
Btw, is there any value in only adding indicator columns containing at least one 1, rather than redundant empty features?
raghavrv commentedon Mar 30, 2016
For the example the census income data set (the original one with the missing values is a good one). You can see how people conviniently choose not to answer some questions ;)
The other one is some bankruptcy dataset which was quoted in a paper by Ding Simonoff on handling missing values in Decision Trees. I haven't found out the link for such a dataset. Their claim is that in the dataset the probability of a bank going bankrupt is higher when the bank chooses not to reveal data for certain questions (features).
For the second question. Assuming I understood correctly that your question is for columns with no missing data, Yes you are right that it won't add any value but if we choose to ignore such columns in the indicator matrix, I'm afraid it would make it difficult for the user to match the column in the indicator matrix with the corresponding column in the feature matrix...
giorgiop commentedon Mar 30, 2016
The motivation is the following: imputation implicitly discards the information that certain examples (rows) had missing values originally. Therefore, before imputation, we add a column for each feature that has at least one missing a value. The additional column is 0 everywhere, except that is it 1 when the corresponding value is missing.
There is no need to double the size of the input in general. Columns should only be concatenated to features that have missing values. This avoids redundancies.
jnothman commentedon Mar 30, 2016
I don't think
imputed_features_ = [1, 2, 4, 7]is cumbersome to create, or to use! Also,get_feature_namescan help.giorgiop commentedon Mar 30, 2016
True. That's a case where features names #6425 would be very useful.
36 remaining items
amueller commentedon Dec 14, 2016
@jnothman I'm not entirely sure I understand the motivation for the design. You want to keep the complexity in the
Imputersmall?I don't know about all the issues the previous implementation had.
As long as adding the features is easy to do and doesn't require a
FeatureUnionfor the inexperienced user, I'm ok with adding a class.It seems like a simple thing but I guess it is not?
Have we made a decision on the semantics? We add indicators for features that were missing in training and optionally either error or ignore if other features are missing?
I think the natural thing would be to either have features for the ones missing in train, for all features, or for a specified subset of features. ("missing_indicators in ["none", "all", "train", indices/mask]).
We were also discussing the option of having a global "anything missing" feature.
I'm not sure what
axis=1should mean.jnothman commentedon Dec 14, 2016
I think part of the issue in the previous design was trying to handle all the cases in which
Imputerworked, and ideally to do so without duplicating the get_mask operation. Given the surprising complexity of the code, I think modularity will make the code much easier to implement, test and maintain, for aO(mn)cost.Otherwise, the advantage to a separate transformer is mostly that users of external imputers can use it too.
I don't mind any of those bonus features. But I can more easily conceive of their design and documentation in a separate MissingIndicator than integrated into Imputer.
And
axis=1currently means that the missing values are set to a statistic derived from non-missing values in their row. I suspect that the MissingIndicator should work the same independent of axis.amueller commentedon Dec 16, 2016
Ok, I'm fine with an additional class.
maniteja123 commentedon Dec 17, 2016
Hi, it's been long time. I was thinking of giving this a try. AFAIU, the transformer now is just the indicator mask for the missing values and can be used with any imputer. I was hoping to get clarity on the semantics of the new class.
Nonefor ``missing_indicators"axis =1Please let me know if I misunderstood anything. Thanks !
maniteja123 commentedon Dec 17, 2016
I have attempted an initial implementation here. Please do have a look at your convenience and give feedback. Thanks !
raghavrv commentedon Dec 18, 2016
Could you raise it as a PR... It will be easier to review that way... Thanks for working again on this...
maniteja123 commentedon Dec 18, 2016
Yeah sure, but it was a very basic implementation and I wasn't sure if I could complete it. So I thought of not raising a PR in case someone wanted to take it up. Sorry for the delay though..
jnothman commentedon Dec 20, 2016
Unless I've forgotten something, I think the
MissingIndicator's operation should be independent ofaxis. I also don't see the need for acopyparameter.We'll probably integrate this into
Imputervia an option, but initially, yes, let's build it as a separate class. Please add tests, and submit a PR.jnothman commentedon Dec 20, 2016
Rather, please submit a PR and add tests.
pshell1 commentedon May 11, 2017
There's an easy way to know which features were included, though it's slightly different from the design you were discussing. In fact the imputer used to do this (the version that came with Anaconda 2.5). It returned a second value containing a vector of the indices of the columns that remained. The transform method still has this info; if you just change the return statement to:
return X, valid_statistics_indexes
that will do the trick. My code which uses the imputer uses that second value. I'm not sure why it was removed.
jnothman commentedon May 11, 2017
[MRG+1] MissingIndicator transformer (#8075)