简体   繁体   English

如何让J48适合数据

[英]How to let J48 fit data

I have a small question about the J48 from Weka. 关于Weka的J48,我有一个小问题。 I run this algorithm from R, using RWeka. 我使用RWeka从R运行此算法。 Probably an easy solution, but i can't seem to find it on the web. 可能是一个简单的解决方案,但我似乎无法在网络上找到它。 A very small example: 一个非常小的例子:

require(RWeka)
Attr1 <- as.factor(c('0302','0302','0320'))
Attr2 <- as.factor(c('2','1','1'))
Target <- as.factor(c('target1','target2','target3'))
input <- data.frame(Attr1,Attr2,Target)
J48( Target ~ Attr1 + Attr2 , data= input, control= Weka_control(W=list(J48,m=1,U=T)))

I want the fit made by the J48 algorithm to fit on the data. 我希望通过J48算法进行拟合以适合数据。 This means I put the minimal items in the leafs to 1 and I dont prune the tree. 这意味着我将叶子中的最小项设置为1,并且不修剪树。 I get the following output: 我得到以下输出:

J48 pruned tree
------------------
: target1 (3.0/2.0)
Number of Leaves  :     1
Size of the tree :  1

Why doesn't it make Attr1 = 0320 -> target3 or Attr2 = 2 -> target1? 为什么不让Attr1 = 0320-> target3或Attr2 = 2-> target1?

I have simplified your code slightly and identified the problem. 我已经稍微简化了您的代码,并确定了问题所在。 The option for the minimum number of leaves is set with "M", not "m". 最小叶数选项设置为“ M”,而不是“ m”。 I discovered this by first querying the possible options 我通过首先查询可能的选项发现了这一点

WOW(J48)  

The pertinent output of which says: 其相关输出显示:

-M <minimum number of instances>
    Set minimum number of instances per leaf.  (default 2)

The important part of your code then becomes: 然后,代码的重要部分变为:


J48( Target ~ Attr1 + Attr2 , data= input, control= Weka_control(M=1,U=TRUE))

J48 unpruned tree
------------------

Attr1 = 0302
|   Attr2 = 1: target2 (1.0)
|   Attr2 = 2: target1 (1.0)
Attr1 = 0320: target3 (1.0)

Number of Leaves  :     3

Size of the tree :  5

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM