数据挖掘十大经典算法:ID3算法

用途

The ID3 algorithm is used by training on a dataset S to produce adecision tree which is stored in memory. At runtime, this decision tree is used to classify new unseen test cases by working down the decision tree using the values of this test case to arrive at a terminal node that tells you what class this test case belongs to.


基本思想

角度1.  越是小型的决策树越优于大的决策树(尽管如此该算法也不是总是生成最小的树形结构)

角度2. 引入信息论中互信息(信息增益),作为判别因素的度量,即:以信息熵的下降速度作为选取测试属性的标准,所选的测试属性是从根到当前节点的路径上尚未被考虑的具有最高信息增益的属性


【注】信息增益指原有数据集的熵-按某个属性分类后数据集的熵。信息增益越大越好(说明按某个属性分类后比较纯),我们会选择使得信息增益最大的那个属性作为当层节点的标记,再进行递归构造决策树。


算法描述

[plain]  view plain copy
  1. ID3 (Examples, Target_Attribute, Attributes)  
  2.     Create a root node for the tree  
  3.     If all examples are positive, Return the single-node tree Root, with label = +.  
  4.     If all examples are negative, Return the single-node tree Root, with label = -.  
  5.     If number of predicting attributes is empty, then Return the single node tree Root,  
  6.     with label = most common value of the target attribute in the examples.  
  7.     Otherwise Begin  
  8.         A ← The Attribute that best classifies examples.  
  9.         Decision Tree attribute for Root = A.  
  10.         For each possible value, v_i, of A,  
  11.             Add a new tree branch below Root, corresponding to the test A = v_i.  
  12.             Let Examples(v_i) be the subset of examples that have the value v_i for A  
  13.             If Examples(v_i) is empty  
  14.                 Then below this new branch add a leaf node with label = most common target value in the examples  
  15.             Else below this new branch add the subtree ID3 (Examples(v_i), Target_Attribute, Attributes – {A})  
  16.     End  
  17.     Return Root  

算例

If S is a collection of 14 examples with 9 YES and 5 NO examples then

Entropy(S) = - (9/14) Log2 (9/14) - (5/14) Log2 (5/14)= 0.940

Notice entropy is 0 if all members of S belong to the same class(the data is perfectly classified). The range of entropy is 0("perfectly classified") to 1 ("totally random").

Gain(S, A) is information gain of example set S on attribute A is defined as

Gain(S, A) = Entropy(S) -  S((|S v| / |S|) * Entropy(S v))

Where:

S is each value v of all possible values of attribute A

Sv = subset of S for which attribute A has value v

|Sv| = number of elements in Sv

|S| = number of elements in S


Suppose S is a set of 14 examples in which one of the attributes is wind speed. The values of Wind can be Weak or Strong.The classification of these 14 examples are 9 YES and 5 NO. For attribute Wind, suppose there are 8 occurrences of Wind = Weak and 6 occurrences of Wind = Strong. For Wind = Weak, 6 of the examples are YES and 2 are NO. For Wind = Strong, 3 are YES and3 are NO. Therefore

Gain(S,Wind)=Entropy(S)-(8/14)*Entropy(Sweak)-(6/14)*Entropy(Sstrong)

= 0.940 - (8/14)*0.811 - (6/14)*1.00

= 0.048

Entropy(Sweak) = - (6/8)*log2(6/8) - (2/8)*log2(2/8)= 0.811

Entropy(Sstrong) = - (3/6)*log2(3/6) - (3/6)*log2(3/6)= 1.00

For each attribute, the gain is calculated and the highest gain is used in the decision node.

Suppose we want ID3 to decide whether the weather is amenable to playing baseball. Over the course of 2 weeks, data is collected to help ID3 build a decision tree (see table 1).

The target classification is "should we play baseball?"which can be yes or no.

The weather attributes are outlook, temperature, humidity, and wind speed. They can have the following values:

outlook = { sunny, overcast, rain }

temperature = {hot, mild, cool }

humidity = { high, normal }

wind = {weak, strong }

Examples of set S are:

Day

Outlook

Temperature

Humidity

Wind

Play ball

D1SunnyHotHighWeakNo
D2SunnyHotHighStrongNo
D3OvercastHotHighWeakYes
D4RainMildHighWeakYes
D5RainCoolNormalWeakYes
D6RainCoolNormalStrongNo
D7OvercastCoolNormalStrongYes
D8SunnyMildHighWeakNo
D9SunnyCoolNormalWeakYes
D10RainMildNormalWeakYes
D11SunnyMildNormalStrongYes
D12OvercastMildHighStrongYes
D13OvercastHotNormalWeakYes
D14RainMildHighStrongNo

Table 1

We need to find which attribute will be the root node in our decision tree. The gain is calculated for all four attributes:

Gain(S, Outlook) = 0.246

Gain(S, Temperature) = 0.029

Gain(S, Humidity) = 0.151

Gain(S, Wind) = 0.048 (calculated above)

Outlook attribute has the highest gain, therefore it is used as the decision attribute in the root node.

Since Outlook has three possible values, the root node has three branches (sunny, overcast, rain). The next question is "what attribute should be tested at the Sunny branch node?" Since we‘ve used Outlook at the root, we only decide on the remaining three attributes: Humidity, Temperature, or Wind.

Ssunny = {D1, D2, D8, D9, D11} = 5 examples from table1 with outlook = sunny

Gain(Ssunny, Humidity) = 0.970

Gain(Ssunny, Temperature) = 0.570

Gain(Ssunny, Wind) = 0.019

Humidity has the highest gain; therefore, it is used as the decision node. This process goes on until all data is classified perfectly or we run out of attributes.

The final decision = tree

The decision tree can also be expressed in rule format:

IF outlook = sunny AND humidity = high THEN playball = no

IF outlook = rain AND humidity = high THEN playball = no

IF outlook = rain AND wind = strong THEN playball = yes

IF outlook = overcast THEN playball = yes

IF outlook = rain AND wind = weak THEN playball = yes

ID3 has been incorporated in a number of commercial rule-induction packages. Some specific applications include medical diagnosis,credit risk assessment of loan applications, equipment malfunctions by their cause, classification of soybean diseases, and web search classification.



  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值