Search code examples
pythoncoremlcoremltools

How to specify missing feature in coremltools


I have a MLModel with feature names "f0", "f1", etc. Not all the features are presented in the input data, so I trying to call predict() without them. In this case I get error:

RuntimeError: {
    NSLocalizedDescription = "Feature 'f0' not provided.";
}

I also tried None for the missing features, the script just hangs.


Solution

  • I found that you can specify numpy.nan to indicate missing features. My model was converted from XGBoost. And as the DMatrix documentation says:

    missing (float, optional) – Value in the input data which needs to be present as a missing value. If None, defaults to np.nan.