2016-10-03 152 views
0

我正在學習如何在C#中實現簡單的決策樹。有人可以解釋我,它是如何看起來像僞代碼或有一些簡單的教程在C#中實現?執行決策樹

我有這樣的數據集:

enter image description here

(從這裏開始:http://storm.cis.fordham.edu/~gweiss/data-mining/weka-data/weather.nominal.arff

,我已經做了圖形決策樹 enter image description here

(對不起,我的英語)

+1

沒有實現決策樹的方法之一。有很多不同的技術和算法。您可以手動編碼選項。您可以像創建一個決策表一樣創建一個決策表並對其進行查詢。你甚至可以使用一個實際的樹,其節點是規則標籤。找到一個特定的答案,然後將找到一個具有特定路徑的葉節點相同 –

+0

我正在尋找最簡單的方法來實現它...需要一些指南開始。 – Revolt

+0

最簡單的方法是閱讀有關決策樹和實現的內容,並找到最適合您的一個。 –

回答

1

要回答這個問題的一部分,顯然是conc決策樹的ept描述爲here。爲了實現上述類型的決策樹,您可以聲明與您的問題中的表格類型匹配的類。基於這種類型,您需要創建一個樹形數據結構,其中子項的數量不受限制。儘管實際數據僅包含在樹葉中,但最好將基本類型的每個成員定義爲可空。這樣,在每個節點中,您只能設置設置爲其子級特定值的成員。另外,應該表示值爲noyes的節點的數量。

0

我的想法是隻有這個:

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 

我真的不知道,該如何繼續

1

如果您正在構建基於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算法,請到鏈接​​