scikit learn imputing values other than NaN
Question: I'm trying to impute values for different placeholders which represent empty
values in a matrix. For example, I want to impute a value whenever "?" is
present in a numpy 2darray.

To this end I create an `Imputer` like so:

    
    
    from sklearn import preprocessing
    imputer = preprocessing.Imputer(missing_values="?", strategy='mean', axis=0, copy=False)
    data = imputer.fit_transform(data)  
    

But I get this error:

    
    
    /usr/local/lib/python2.7/dist-packages/sklearn/preprocessing/imputation.pyc in _get_mask(X, value_to_mask)
         27 def _get_mask(X, value_to_mask):
         28     """Compute the boolean mask X == missing_values."""
    ---> 29     if value_to_mask == "NaN" or np.isnan(value_to_mask):
         30         return np.isnan(X)
         31     else:
    
    NotImplementedError: Not implemented for this type
    

Am I misunderstanding what `missing_values` can be set to?

I was under the impression it could be any string, not just "NaN", which is
what the scikit-learn source seems to suggest.


Answer: The type `"integer or string"` really means "either an integer, or the string
`'NaN'`". The input to `fit`/`fit_transform` should still be numeric. (The
only reason `"NaN"` is passed as a string is that passing `np.nan` can lead to
confusing situations because it's not equal to itself, i.e. `np.nan == np.nan`
evaluates to `False`.)

