classifiers in scikit-learn that handle nan/null

Short answer

Sometimes missing values are simply not applicable. Imputing them is meaningless. In these cases you should use a model that can handle missing values. Scitkit-learn’s models cannot handle missing values. XGBoost can.


More on scikit-learn and XGBoost

As mentioned in this article, scikit-learn’s decision trees and KNN algorithms are not (yet) robust enough to work with missing values. If imputation doesn’t make sense, don’t do it.

Consider situtations when imputation doesn’t make sense.

keep in mind this is a made-up example

Consider a dataset with rows of cars (“Danho Diesel”, “Estal Electric”, “Hesproc Hybrid”) and columns with their properties (Weight, Top speed, Acceleration, Power output, Sulfur Dioxide Emission, Range).

Electric cars do not produce exhaust fumes – so the Sulfur dioxide emission of the Estal Electric should be a NaN-value (missing). You could argue that it should be set to 0 – but electric cars cannot produce sulfur dioxide. Imputing the value will ruin your predictions.

As mentioned in this article, scikit-learn’s decision trees and KNN algorithms are not (yet) robust enough to work with missing values. If imputation doesn’t make sense, don’t do it.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)