# Does DecisionTreeClassifier support missing data in the predictors?

**URL:** https://discourse.julialang.org/t/does-decisiontreeclassifier-support-missing-data-in-the-predictors/71013
**Category:** Machine Learning
**Tags:** mlj
**Created:** [November 5, 2021, 4:17pm UTC](https://discourse.julialang.org/t/does-decisiontreeclassifier-support-missing-data-in-the-predictors/71013 "2021-11-05T16:17:17Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Rahul](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rahul/32/30545_2.png) [@Rahul](https://discourse.julialang.org/u/Rahul)
#### Post date: [November 5, 2021, 4:17pm UTC](https://discourse.julialang.org/t/does-decisiontreeclassifier-support-missing-data-in-the-predictors/71013/1 "2021-11-05T16:17:17Z")

</div>

I cannot pass missing data to train DecisionTreeClassifier in MLJ. Is this not supported? Although the `machine` function gave me a warning, I tried to run fit! and it threw and error that the scitype of X isn’t supported.

 ![image](https://global.discourse-cdn.com/julialang/original/3X/1/d/1d1b3f5d637a91d28346c4d6eb307487fd755ee0.png)

---

<div class="post-metadata">

### Author: ![ablaom](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ablaom/32/4889_2.png) [@ablaom](https://discourse.julialang.org/u/ablaom)
#### Post date: [November 6, 2021, 6:28pm UTC](https://discourse.julialang.org/t/does-decisiontreeclassifier-support-missing-data-in-the-predictors/71013/2 "2021-11-06T18:28:11Z")

</div>

@Rahul Thanks for reporting. Which DecisionTreeClassifier are you using? The one from `DecisionTree.jl` is not compatible with missing values. It assumes any feature is ordered.

However, I believe the BetaML version _does_ support missing values but there I see there is a bug in the input scitype declaration which would trigger the warning you are seeing. If you ignore the warning you should be fine, assuming that is the packages you are using. It can be loaded with

```julia
BetaMLTree = @load DecisionTreeClassifier pkg=BetaML add=true
tree = BetaMLTree()

```

I’ve posted an issue [here](https://github.com/sylvaticus/BetaML.jl/issues/28) to request fixing the scitype.

cc @sylvaticus

---

<div class="post-metadata">

### Author: ![Rahul](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rahul/32/30545_2.png) [@Rahul](https://discourse.julialang.org/u/Rahul)
#### Post date: [November 7, 2021, 3:55pm UTC](https://discourse.julialang.org/t/does-decisiontreeclassifier-support-missing-data-in-the-predictors/71013/3 "2021-11-07T15:55:56Z")

</div>

Thank you for your response @ablaom. The BetaML DecisionTree works as expected!

I have one more question. I am getting the same error of unable to fit missing values by `using XGBoost` XGBoostClassifier(). I checked that BetaML does not provide XGBoostClassifier. Do you know if there are any other packages that allow a dataset with missing values for training XGBoost?

---

<div class="post-metadata">

### Author: ![sylvaticus](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sylvaticus/32/203883_2.png) [@sylvaticus](https://discourse.julialang.org/u/sylvaticus)
#### Post date: [November 8, 2021, 8:26pm UTC](https://discourse.julialang.org/t/does-decisiontreeclassifier-support-missing-data-in-the-predictors/71013/4 "2021-11-08T20:26:43Z")

</div>

I implemented the MLJ interface fix as suggested by ablaom, so it should now work without the warning

However be aware that with missing data the algorithm is much slower. You may consider imputing the missing values with `MissingImputator` (also in BetaML) and then running the DecisionTree algorithm on non-missing values.
