簡體   English   中英

實現決策樹

[英]Implementing decision tree

我正在學習如何在 C# 中實現簡單的決策樹。 有人可以解釋一下,它在偽代碼中的樣子,或者有一些在 c# 中實現的簡單教程嗎?

我有這個數據集:

在此處輸入圖片說明

(來自: http : //storm.cis.fordham.edu/~gweiss/data-mining/weka-data/weather.nominal.arff

我已經完成了圖形決策樹在此處輸入圖片說明

(對不起我的英語不好)


我的想法只有這樣:

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

我真的不知道,如何繼續

為了部分回答這個問題,顯然這里描述了決策樹的概念。 要為上述類型實現決策樹,您可以聲明一個與問題中表中的類型匹配的類。 基於該類型,您需要創建一個樹數據結構,其中子節點的數量不受限制。 雖然實際數據僅包含在葉子中,但最好將基本類型的每個成員定義為可為空。 這樣,在每個節點中,您只能設置被設置為其子節點的特定值的成員。 此外,還應表示值為noyes的節點數。

如果是基於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 算法的更多信息,請轉到鏈接ID3 算法

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM