如何在 RWeka 中获取分类值?

How to get classification values in RWeka?

任何人都可以解释我如何从 RWeka 包中的 J48 制作的决策树中获得每次休假的结果吗?

例如,我们在 R 中有这个鸢尾花数据集:

 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; Petal.Width <= 1.7; Petal.Length <= 4.9 结果杂色 97,9%。和 2.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