R新手一枚,知道可以使用 rpart、party 等包完成决策树建模、分析等操作。
最近在 Introduction to Data Mining(作者 PANG-NING TANG)看到一算法,描述如下。
想编写函数实现并和 rpart 等包生成的结果进行比较,望指教![s:19]
<br />
TreeGrouth(E, F)</p>
<p>if stopping_cond(E, F) = true then<br />
leaf = createNode()<br />
leaf.label = Classify(E)<br />
return leaf<br />
else<br />
root = createNode()<br />
root.test_cond = find_best_split(E, F)<br />
let V = {v|v is a possible outcome of root.test_cond}<br />
for each v belongs to V do<br />
Ev = {e|root.test_cond(e) = v and e belongs to E}<br />
child = TreeGrowth(E, F)<br />
add child as descendent of root and label the edge (root -> child) as v<br />
end for<br />
end if<br />
return root<br />
</p>