【问题标题】:Want to plot a decision tree in R got this error: (sapply(split, tail, 1) %in% mf_levels[[var_id]]) is not TRUE想要在 R 中绘制决策树得到这个错误: (sapply(split, tail, 1) %in% mf_levels[[var_id]]) is not TRUE
【发布时间】:2016-06-22 13:38:33
【问题描述】:

我使用 J48 在下面生成一个决策树,当我想使用它来绘制它时

if(require("party",quietly=TRUE)) plot(fit_1)

它给出了一个错误:

错误:all(sapply(split, tail, 1) %in% mf_levels[[var_id]]) 不是 TRUE

这个错误是什么意思?

【问题讨论】:

    标签: r plot decision-tree


    【解决方案1】:

    我偶然发现了同样的问题,并向 CRAN 社区寻求帮助。该问题主要依赖于使用非 ASCII 标签的数据文件的编码,而在导入文件时没有正确声明它们。

    Achim Zeileis(partykit 库的管理员)提供了以下答案 -->

    为避免该问题,您可以:

    • 避免使用非 ASCII 标签,这通常是最可靠的解决方案,您不必太注意自己在做什么。

    • 或者您正确声明数据文件的编码如下:

    dataframe <- read.csv("mynonASCII_data.csv", header=T,sep=',',
    **encoding = "proper_encoding"**)
    
    #proper encoding could be any non-ASCII encoding such as 'latin1' for example
    
    resultJ48 <- J48(class~., dataframe, control = Weka_control(M = 2, C =0.5))
    
    x <- as.party(resultJ48)
    

    as.party 现在应该适用于您的情节

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-12-18
      • 2013-02-09
      • 1970-01-01
      • 2017-01-30
      • 2017-10-23
      • 2019-01-03
      • 2018-12-21
      相关资源
      最近更新 更多