SCM

Forum: help

Monitor Forum | Start New Thread Start New Thread
RE: [bug] Error in handling tree having a split on logical variable [ Reply ]
By: Martin Gubri on 2017-08-17 23:10
[forum:45266]
Thanks a lot for your help and your very quick reply. I will try to take a look too, if I found some time.

RE: [bug] Error in handling tree having a split on logical variable [ Reply ]
By: Achim Zeileis on 2017-08-17 21:34
[forum:45265]
We do so for native creation of party trees (e.g., via ctree()) but apparently not for the internal coercion in the case that you found. Will have a look...

RE: [bug] Error in handling tree having a split on logical variable [ Reply ]
By: Martin Gubri on 2017-08-17 21:32
[forum:45264]
Great. Thanks a lot for your help Achim.
May I suggest to add a check on the classes of variables in order to throw an explicit error if one isn't supported? I think it can help new users to understand more easily the problem.

RE: [bug] Error in handling tree having a split on logical variable [ Reply ]
By: Achim Zeileis on 2017-08-16 22:11
[forum:45260]
Martin, thanks for the report. At the moment "logical" is indeed not supported. It is recommended to use a 2-level "factor" instead (rather than a numeric variable). But we'll discuss whether it may make sense to support logical variables as well (as we're working on a major update of the package anyway).

[bug] Error in handling tree having a split on logical variable [ Reply ]
By: Martin Gubri on 2017-08-16 04:25
[forum:45259]
Dear all,

I think there is a bug in the handling of trees that have a split on a logical variable. Here is a small piece of code to reproduce it:

```
library(partykit)
library(RWeka)
iris$Petal.Length <- iris$Petal.Length > mean(iris$Petal.Length)
m1 <- J48(Species ~ Petal.Length, data = iris)
m1

# J48 pruned tree
# ------------------
#
# Petal.Length = FALSE: setosa (57.0/7.0)
# Petal.Length = TRUE: virginica (93.0/43.0)
#
# Number of Leaves : 2
# Size of the tree : 3

as.party(m1)
# Error: length(breaks) == 1 && !is.na(breaks) is not TRUE
# In addition: Warning message:
# In unique(as.numeric(sapply(split, tail, 1))) : NAs introduced by coercion
```

If the logical variable is converted to numeric, the tree is correctly parsed.
iris$Petal.Length <- as.numeric(iris$Petal.Length)


I'm not sure if this is a bug in as.party.Weka_tree() only, or if other tree classes are also impacted.

I'm available for any question, comment, etc.
Thanks a lot,
Best.

Thanks to:
Vienna University of Economics and Business Powered By FusionForge