我正在学习如何在C#中实现简单的决策树。有人可以解释我,它是如何看起来像伪代码或有一些简单的教程在C#中实现?执行决策树
我有这样的数据集:
(从这里开始:http://storm.cis.fordham.edu/~gweiss/data-mining/weka-data/weather.nominal.arff)
(对不起,我的英语)
我正在学习如何在C#中实现简单的决策树。有人可以解释我,它是如何看起来像伪代码或有一些简单的教程在C#中实现?执行决策树
我有这样的数据集:
(从这里开始:http://storm.cis.fordham.edu/~gweiss/data-mining/weka-data/weather.nominal.arff)
(对不起,我的英语)
要回答这个问题的一部分,显然是conc决策树的ept描述为here。为了实现上述类型的决策树,您可以声明与您的问题中的表格类型匹配的类。基于这种类型,您需要创建一个树形数据结构,其中子项的数量不受限制。尽管实际数据仅包含在树叶中,但最好将基本类型的每个成员定义为可空。这样,在每个节点中,您只能设置设置为其子级特定值的成员。另外,应该表示值为no
和yes
的节点的数量。
我的想法是只有这个:
if outlook = "overcast" then no
if outlook = "sunny" and humidity = "normal" then yes
if outlook = "sunny" and humidity = "high" then no
if outlook = "rain" and wind = "true" then no
if outlook = "rain" and wind = "fasle" then yes
我真的不知道,该如何继续
如果您正在构建基于ID3算法的决策树,你可以参考这个伪代码。
ID3 (Examples, Target_Attribute, Attributes)
Create a root node for the tree
If all examples are positive, Return the single-node tree Root, with label = +.
If all examples are negative, Return the single-node tree Root, with label = -.
If number of predicting attributes is empty, then Return the single node tree Root,
with label = most common value of the target attribute in the examples.
Otherwise Begin
A ← The Attribute that best classifies examples.
Decision Tree attribute for Root = A.
For each possible value, vi, of A,
Add a new tree branch below Root, corresponding to the test A = vi.
Let Examples(vi) be the subset of examples that have the value vi for A
If Examples(vi) is empty
Then below this new branch add a leaf node with label = most common target value in the examples
Else below this new branch add the subtree ID3 (Examples(vi), Target_Attribute, Attributes – {A})
End
Return Root
如果您想了解更多关于ID3算法,请到链接
没有实现决策树的方法之一。有很多不同的技术和算法。您可以手动编码选项。您可以像创建一个决策表一样创建一个决策表并对其进行查询。你甚至可以使用一个实际的树,其节点是规则标签。找到一个特定的答案,然后将找到一个具有特定路径的叶节点相同 –
我正在寻找最简单的方法来实现它...需要一些指南开始。 – Revolt
最简单的方法是阅读有关决策树和实现的内容,并找到最适合您的一个。 –