Missing values in scikits machine learning

Vladtn picture Vladtn · Feb 20, 2012 · Viewed 35.7k times · Source

Is it possible to have missing values in scikit-learn ? How should they be represented? I couldn't find any documentation about that.

Answer

Fred Foo picture Fred Foo · Feb 20, 2012

Missing values are simply not supported in scikit-learn. There has been discussion on the mailing list about this before, but no attempt to actually write code to handle them.

Whatever you do, don't use NaN to encode missing values, since many of the algorithms refuse to handle samples containing NaNs.

The above answer is outdated; the latest release of scikit-learn has a class Imputer that does simple, per-feature missing value imputation. You can feed it arrays containing NaNs to have those replaced by the mean, median or mode of the corresponding feature.