交互式决策树

机器算法验证 sas 大车 威卡
2022-03-24 04:54:05

我想知道是否有像 SAS Enterprise Mining 那样以交互方式构建决策树的免费工具。我习惯与 Weka 合作。但没有什么适合我的需要。我希望在拆分每个节点之前,程序会询问用户选择哪个属性(可能来自“最佳”属性列表)。我看到在 SAS 中实现了它。我应该写一些代码来得到我想要的吗?

谢谢

2个回答

试试Orange Canvas,它会给你构建交互式决策树的选项。

尝试树状图下的示例。您可以根据需要使其具有交互性。

require(graphics); require(utils)

hc <- hclust(dist(USArrests), "ave")
(dend1 <- as.dendrogram(hc)) # "print()" method
str(dend1)          # "str()" method
str(dend1, max = 2) # only the first two sub-levels

op <- par(mfrow= c(2,2), mar = c(5,2,1,4))
plot(dend1)
## "triangle" type and show inner nodes:
plot(dend1, nodePar=list(pch = c(1,NA), cex=0.8, lab.cex = 0.8),
      type = "t", center=TRUE)
plot(dend1, edgePar=list(col = 1:2, lty = 2:3),
      dLeaf=1, edge.root = TRUE)
plot(dend1, nodePar=list(pch = 2:1,cex=.4*2:1, col = 2:3), 
      horiz=TRUE)

编辑1 =====================================

交互性取决于您想要做什么。这一切都归结为数据的结构plot为了更容易看到发生了什么,我将只使用上面示例中的前 3 行数据:

#Use only the first 3 lines from USArrests
(df <- USArrests[1:3,])

#Perform the hc analysis
(hcdf <- hclust(dist(df), "ave"))

#Plot the results
plot(hcdf)

#Look at the names of hcdf
names(hcdf)

#Look at the structure of hcdf
dput(hcdf)

下一段是上述dput语句的输出。这个结构告诉plot如何绘制树。

structure(list(merge = structure(c(-1L, -3L, -2L, 1L), .Dim = c(2L,
2L)), height = c(37.1770090243957, 54.8004107236398), order = c(3L,
1L, 2L), labels = c("Alabama", "Alaska", "Arizona"), method = "average",
   call = hclust(d = dist(df), method = "ave"), dist.method = "euclidean"),
.Names = c("merge", "height", "order", "labels", "method", "call", "dist.method"),
class = "hclust")

在此处输入图像描述

您可以轻松更改数据并查看其plot作用。只需从屏幕复制/粘贴structure语句并将其分配给新变量,进行更改并绘制它。

newvar <- structure(list(merge = structure(c(-1L, -3L, -2L, 1L), .Dim = c(2L, 2L)), height = c(37.1770090243957, 54.8004107236398), order = c(3L, 1L, 2L), labels = c("Alabama", "Alaska", "Arizona"), method = "average",     call = hclust(d = dist(df), method = "ave"), dist.method = "euclidean"), .Names = c("merge", "height", "order", "labels", "method", "call", "dist.method"), class = "hclust")

plot(newvar)

就使集群更具交互性而言,您必须探索不同的方法并确定您想要做什么。

http://cran.cnr.berkeley.edu/web/views/Cluster.html

http://wiki.math.yorku.ca/index.php/R:_Cluster_analysis

http://www.statmethods.net/advstats/cluster.html

http://www.statmethods.net/advstats/cart.html