【问题标题】:How to get classification values in RWeka?如何在 RWeka 中获取分类值?
【发布时间】:2020-03-14 14:44:25
【问题描述】:

谁能解释我如何从 RWeka 包中获得 J48 生成的决策树中每次休假的结果?

例如,我们在 R 中有这个 iris 数据集:

 library(RWeka)
 m1 <- J48(Species ~ ., data = iris)
 m1

在预测中,我想使用休假中的比例。我尝试使用 Partykit 包,但它仍然看起来很复杂,只是为了得到每个假期的比例。

 library(partykit)
 pres <- as.party(m1)
 partykit:::.list.rules.party(pres)

至少我得到了列表中的叶子数,但是找不到概率。

pres

Model formula:
Species ~ Sepal.Length + Sepal.Width + Petal.Length + Petal.Width

Fitted party:
[1] root
|   [2] Petal.Width <= 0.6: setosa (n = 50, err = 0.0%)
|   [3] Petal.Width > 0.6
|   |   [4] Petal.Width <= 1.7
|   |   |   [5] Petal.Length <= 4.9: versicolor (n = 48, err = 2.1%)
|   |   |   [6] Petal.Length > 4.9
|   |   |   |   [7] Petal.Width <= 1.5: virginica (n = 3, err = 0.0%)
|   |   |   |   [8] Petal.Width > 1.5: versicolor (n = 3, err = 33.3%)
|   |   [9] Petal.Width > 1.7: virginica (n = 46, err = 2.2%)

Number of inner nodes:    4
Number of terminal nodes: 5

因此,作为预测,我想要例如 Petal.Width > 0.6 的新数据点的结果;花瓣宽度 如何获得这些预测?

【问题讨论】:

    标签: r decision-tree rweka j48


    【解决方案1】:

    你的观点不是观点。如果您完全指定一个点,您只需将其插入predict 函数即可。例如,我将生成一个符合规范的点,但与其他虹膜点不同——然后对其进行分类。

    ## Generate wild new point
    NewPoint = iris[1,]
    NewPoint[1,3:4] = c(2.0,1.7)
    NewPoint
    Sepal.Length Sepal.Width Petal.Length Petal.Width Species
    1          5.1         3.5            2         1.7  setosa
    
    ## Look at where the new point is
    plot(iris[,3:4], pch=20, col=rainbow(3, alpha=0.3)[iris$Species])
    points(NewPoint[,3:4], pch=16, col="orange")
    

    ## Get the probability from the model
    predict(m1, newdata = NewPoint, type = "probability")
      setosa versicolor  virginica
    1      0  0.9791667 0.02083333
    

    【讨论】:

      猜你喜欢
      • 2018-09-05
      • 2018-01-26
      • 2019-11-11
      • 1970-01-01
      • 2013-12-01
      • 2016-05-16
      • 2019-09-27
      • 1970-01-01
      • 2022-06-05
      相关资源
      最近更新 更多