- 浏览: 79037 次
- 性别:
- 来自: 拜月神教
最新评论
-
huangfenghit:
你绝对的大牛~
答复: 阿里巴巴面试感言 -
liuxuejin:
好!慢慢下载来看看
区间树 -
xiaobian:
看不懂,怎么知道是讲的好呢 ?
数据挖掘 决策树ID3算法原理 -
longay00:
不错,很牛,不过没有原理与实验很难相信它的正确性。从代码上看, ...
决策树C4.5算法 -
yangguo:
用我的study方法就可以了。
答复: java最优算法讨论
上一篇博客写了ID3算法的简单实现
这一篇讲讲ID3的原理
写这个算法是由于某同事的同学的毕业设计,关系够复杂的了==|||,写完这个算法,突然对数据挖掘有了兴趣,决定把C4.5,C5.0算法也一并实现,并且再研究一下数据挖掘的分类算法
其实这篇原理,没有我自己的内容。。。引用某人blog的东东吧(我本人倒是很反感抄袭的)
首先奉上blog作者:神威异度
虽然未曾与之交谈,不过经历千辛万苦的搜索之后,终于在他的blog发现了有价值的东西(这里要提一下,想要在国内搜索出有价值的东西真不容易,到处充斥着转载,小小鄙视一下我自己先),在这里万分感谢神威异度同学
奉上blog链接:http://www.blog.edu.cn/user2/huangbo929/archives/2006/1533249.shtml
再不厌其烦的把人家的东西copy到我这里。
决策树生成原理
Abstract
This paper details the ID3 classification algorithm. Very simply, ID3 builds a decision tree from a fixed set of examples. The resulting tree is used to classify future samples. The example has several attributes and belongs to a class (like yes or no). The leaf nodes of the decision tree contain the class name whereas a non-leaf node is a decision node. The decision node is an attribute test with each branch (to another decision tree) being a possible value of the attribute. ID3 uses information gain to help it decide which attribute goes into a decision node. The advantage of learning a decision tree is that a program, rather than a knowledge engineer, elicits knowledge from an expert.
Introduction
J. Ross Quinlan originally developed ID3 at the University of Sydney. He first presented ID3 in 1975 in a book, Machine Learning, vol. 1, no. 1. ID3 is based off the Concept Learning System (CLS) algorithm. The basic CLS algorithm over a set of training instances C:
Step 1: If all instances in C are positive, then create YES node and halt.
If all instances in C are negative, create a NO node and halt.
Otherwise select a feature, F with values v1, ..., vn and create a decision node.
Step 2: Partition the training instances in C into subsets C1, C2, ..., Cn according to the values of V.
Step 3: apply the algorithm recursively to each of the sets Ci.
Note, the trainer (the expert) decides which feature to select.
ID3 improves on CLS by adding a feature selection heuristic. ID3 searches through the attributes of the training instances and extracts the attribute that best separates the given examples. If the attribute perfectly classifies the training sets then ID3 stops; otherwise it recursively operates on the n (where n = number of possible values of an attribute) partitioned subsets to get their "best" attribute. The algorithm uses a greedy search, that is, it picks the best attribute and never looks back to reconsider earlier choices.
Discussion
ID3 is a nonincremental algorithm, meaning it derives its classes from a fixed set of training instances. An incremental algorithm revises the current concept definition, if necessary, with a new sample. The classes created by ID3 are inductive, that is, given a small set of training instances, the specific classes created by ID3 are expected to work for all future instances. The distribution of the unknowns must be the same as the test cases. Induction classes cannot be proven to work in every case since they may classify an infinite number of instances. Note that ID3 (or any inductive algorithm) may misclassify data.
Data Description
The sample data used by ID3 has certain requirements, which are:
Attribute-value description - the same attributes must describe each example and have a fixed number of values.
Predefined classes - an example's attributes must already be defined, that is, they are not learned by ID3.
Discrete classes - classes must be sharply delineated. Continuous classes broken up into vague categories such as a metal being "hard, quite hard, flexible, soft, quite soft" are suspect.
Sufficient examples - since inductive generalization is used (i.e. not provable) there must be enough test cases to distinguish valid patterns from chance occurrences.
Attribute Selection
How does ID3 decide which attribute is the best? A statistical property, called information gain, is used. Gain measures how well a given attribute separates training examples into targeted classes. The one with the highest information (information being the most useful for classification) is selected. In order to define gain, we first borrow an idea from information theory called entropy. Entropy measures the amount of information in an attribute.
Given a collection S of c outcomes
Entropy(S) = S -p(I) log2 p(I)
where p(I) is the proportion of S belonging to class I. S is over c. Log2 is log base 2.
Note that S is not an attribute but the entire sample set.
Example 1
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 ((|Sv| / |S|) * Entropy(Sv))
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
Example 2
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 and 3 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.
Example of ID3
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
D1 Sunny Hot High Weak No
D2 Sunny Hot High Strong No
D3 Overcast Hot High Weak Yes
D4 Rain Mild High Weak Yes
D5 Rain Cool Normal Weak Yes
D6 Rain Cool Normal Strong No
D7 Overcast Cool Normal Strong Yes
D8 Sunny Mild High Weak No
D9 Sunny Cool Normal Weak Yes
D10 Rain Mild Normal Weak Yes
D11 Sunny Mild Normal Strong Yes
D12 Overcast Mild High Strong Yes
D13 Overcast Hot Normal Weak Yes
D14 Rain Mild High Strong No
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 in example 2)
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=92ve 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 table 1 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.
Conclusion
The discussion and examples given show that ID3 is easy to use. Its primary use is replacing the expert who would normally build a classification tree by hand. As industry has shown, ID3 has been effective.
这一篇讲讲ID3的原理
写这个算法是由于某同事的同学的毕业设计,关系够复杂的了==|||,写完这个算法,突然对数据挖掘有了兴趣,决定把C4.5,C5.0算法也一并实现,并且再研究一下数据挖掘的分类算法
其实这篇原理,没有我自己的内容。。。引用某人blog的东东吧(我本人倒是很反感抄袭的)
首先奉上blog作者:神威异度
虽然未曾与之交谈,不过经历千辛万苦的搜索之后,终于在他的blog发现了有价值的东西(这里要提一下,想要在国内搜索出有价值的东西真不容易,到处充斥着转载,小小鄙视一下我自己先),在这里万分感谢神威异度同学
奉上blog链接:http://www.blog.edu.cn/user2/huangbo929/archives/2006/1533249.shtml
再不厌其烦的把人家的东西copy到我这里。
决策树生成原理
Abstract
This paper details the ID3 classification algorithm. Very simply, ID3 builds a decision tree from a fixed set of examples. The resulting tree is used to classify future samples. The example has several attributes and belongs to a class (like yes or no). The leaf nodes of the decision tree contain the class name whereas a non-leaf node is a decision node. The decision node is an attribute test with each branch (to another decision tree) being a possible value of the attribute. ID3 uses information gain to help it decide which attribute goes into a decision node. The advantage of learning a decision tree is that a program, rather than a knowledge engineer, elicits knowledge from an expert.
Introduction
J. Ross Quinlan originally developed ID3 at the University of Sydney. He first presented ID3 in 1975 in a book, Machine Learning, vol. 1, no. 1. ID3 is based off the Concept Learning System (CLS) algorithm. The basic CLS algorithm over a set of training instances C:
Step 1: If all instances in C are positive, then create YES node and halt.
If all instances in C are negative, create a NO node and halt.
Otherwise select a feature, F with values v1, ..., vn and create a decision node.
Step 2: Partition the training instances in C into subsets C1, C2, ..., Cn according to the values of V.
Step 3: apply the algorithm recursively to each of the sets Ci.
Note, the trainer (the expert) decides which feature to select.
ID3 improves on CLS by adding a feature selection heuristic. ID3 searches through the attributes of the training instances and extracts the attribute that best separates the given examples. If the attribute perfectly classifies the training sets then ID3 stops; otherwise it recursively operates on the n (where n = number of possible values of an attribute) partitioned subsets to get their "best" attribute. The algorithm uses a greedy search, that is, it picks the best attribute and never looks back to reconsider earlier choices.
Discussion
ID3 is a nonincremental algorithm, meaning it derives its classes from a fixed set of training instances. An incremental algorithm revises the current concept definition, if necessary, with a new sample. The classes created by ID3 are inductive, that is, given a small set of training instances, the specific classes created by ID3 are expected to work for all future instances. The distribution of the unknowns must be the same as the test cases. Induction classes cannot be proven to work in every case since they may classify an infinite number of instances. Note that ID3 (or any inductive algorithm) may misclassify data.
Data Description
The sample data used by ID3 has certain requirements, which are:
Attribute-value description - the same attributes must describe each example and have a fixed number of values.
Predefined classes - an example's attributes must already be defined, that is, they are not learned by ID3.
Discrete classes - classes must be sharply delineated. Continuous classes broken up into vague categories such as a metal being "hard, quite hard, flexible, soft, quite soft" are suspect.
Sufficient examples - since inductive generalization is used (i.e. not provable) there must be enough test cases to distinguish valid patterns from chance occurrences.
Attribute Selection
How does ID3 decide which attribute is the best? A statistical property, called information gain, is used. Gain measures how well a given attribute separates training examples into targeted classes. The one with the highest information (information being the most useful for classification) is selected. In order to define gain, we first borrow an idea from information theory called entropy. Entropy measures the amount of information in an attribute.
Given a collection S of c outcomes
Entropy(S) = S -p(I) log2 p(I)
where p(I) is the proportion of S belonging to class I. S is over c. Log2 is log base 2.
Note that S is not an attribute but the entire sample set.
Example 1
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 ((|Sv| / |S|) * Entropy(Sv))
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
Example 2
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 and 3 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.
Example of ID3
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
D1 Sunny Hot High Weak No
D2 Sunny Hot High Strong No
D3 Overcast Hot High Weak Yes
D4 Rain Mild High Weak Yes
D5 Rain Cool Normal Weak Yes
D6 Rain Cool Normal Strong No
D7 Overcast Cool Normal Strong Yes
D8 Sunny Mild High Weak No
D9 Sunny Cool Normal Weak Yes
D10 Rain Mild Normal Weak Yes
D11 Sunny Mild Normal Strong Yes
D12 Overcast Mild High Strong Yes
D13 Overcast Hot Normal Weak Yes
D14 Rain Mild High Strong No
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 in example 2)
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=92ve 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 table 1 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.
Conclusion
The discussion and examples given show that ID3 is easy to use. Its primary use is replacing the expert who would normally build a classification tree by hand. As industry has shown, ID3 has been effective.
发表评论
-
庞果英雄会 覆盖数字
2013-11-14 15:13 856庞果覆盖数字原题如下 给定整数区间[a,b]和整数区间[x, ... -
2-3 tree
2013-10-09 17:10 772package com.leon.cc; imp ... -
编译原理生成LL1预测分析表
2013-08-11 20:47 5850package com.leon; impo ... -
应用倍增法后缀数组以及RMQ求解N个字符串最长公共子串问题
2011-11-30 16:35 1464/** * @see IOI2009国家集训队论文《后 ... -
谷哥的KOF连招问题
2010-10-09 14:38 1533传说问题是这样的 玩过KOF(拳皇)的人都知道,玩的时候会连招 ... -
KOF
2010-10-09 00:13 0package org.struct.trietree; ... -
ACM/ICPC HDU 1195
2010-09-06 10:37 1897本年度还有8篇博客需要完成 开篇前附加一个看完《盗梦空间》的我 ... -
答复: 阿里巴巴面试感言
2009-10-09 22:27 2185好吧,我承认我闲的蛋疼 问题:3000万条的记录取最大的前50 ... -
正向最大匹配改进算法
2009-05-26 22:11 5893AD.: 2年J2EE经验,熟悉常用数据结构算法,熟悉常 ... -
决策树C4.5算法
2009-05-19 02:05 5259数据挖掘中决策树C4.5预测算法实现(半成品,还要写规则后 ... -
区间树
2008-07-18 15:47 2191package acmcode; /** * ... -
红黑树初版
2008-07-16 17:20 1610package acmcode; /** * R ... -
四则运算的中缀转后缀,逆波兰表达式求值
2008-04-23 23:10 9086首先描述问题 给定一 ... -
最大0,1子矩阵
2008-04-20 21:16 6087首先描述一下问题 /** * * 时间限制(普 ... -
决策树ID3算法
2008-04-01 22:18 7607算了,还是自己修正一个BUG.... package gr ... -
ext2.0 的XMLWriter
2008-02-20 21:04 1285做ext相关的一个example项目,把我们的客户端移植成ex ... -
树与哈夫曼树
2008-02-20 20:50 1593package tree; public ... -
LCS与图算法
2008-02-20 20:46 1236求两个字符串最长公共子串的问题。大体解法是用一个矩阵来记录两个 ... -
《程序员》算法擂台:骑士聚会
2008-02-20 20:40 1217在8×8的棋盘上分布着n个骑士,他们想约在某一个格中聚会。骑士 ...
相关推荐
总结起来,数据挖掘中的ID3算法是一种高效的决策树学习方法,通过C++实现可以加深对算法的理解并应用于实际问题。在这个过程中,不仅需要掌握ID3算法的理论知识,还要熟悉C++编程,尤其是数据结构和递归算法的应用。...
### 决策树ID3算法的实例解析 #### 一、引言 本文将深入探讨决策树ID3算法的核心概念及其应用案例。ID3(Iterative Dichotomiser 3)算法是由Ross Quinlan在1986年提出的一种用于生成决策树的经典算法。在数据挖掘...
大学 ppt 数据挖掘 决策树 原理 算法 id3 迭代二元树 3代
决策树是一种常用的数据挖掘技术...通过这个项目,不仅可以学习到决策树ID3算法的基本原理,还能掌握如何在实际开发中运用MFC进行GUI编程。这有助于提升软件开发能力和数据分析技能,为今后从事相关工作打下坚实基础。
1986年,J.R.Quinlan提出了ID3算法,该算法基于信息增益原理来构造决策树。在ID3的基础上,Quinlan又提出了C4.5算法,它在很多方面对ID3进行了改进。这些改进包括处理连续属性、防止过拟合以及能够处理缺失值等。 ...
决策树ID3算法是机器学习领域中的一种经典分类方法,主要应用于数据挖掘和模式识别。在C语言课程设计中,实现ID3算法可以帮助学生深入理解数据处理和算法逻辑。ID3算法是由Ross Quinlan提出的,它基于信息熵和信息...
本文介绍了如何使用Java实现决策树ID3算法,包括算法原理、实现细节及代码解析。通过这种方式,可以更好地理解ID3算法的工作机制,并掌握其实现方法。此外,文件读取部分也是实现决策树算法的重要组成部分,确保了...
总结来说,"数据挖掘 决策树代码"涉及了决策树理论、ID3算法以及在不同编程语言中的实现,而"fp_tree合集"则可能涵盖了频繁模式挖掘的内容。理解并掌握这些知识对于进行数据驱动的决策分析和预测具有重要意义。在...
数据挖掘中的决策树算法是一种分类方法,它在数据挖掘过程中起着至关重要的作用。决策树算法通过树形结构来展现数据的分类规则,能够有效地分析数据、预测未来的趋势并提取出决策规则。在数据挖掘的应用中,决策树...
决策树是一种常用的数据挖掘算法,它通过学习样本数据构建出一棵树形模型,用于预测未知数据的类别。在Java中实现决策树可以帮助开发者理解和应用这种算法。本文将深入探讨决策树的基本原理、主要步骤以及如何在Java...
常见的决策树算法有ID3、C4.5和CART,它们各有优缺点,适用于不同的数据类型和问题。 【压缩包子文件的文件名称列表】中,虽然有一个文件名为"数据挖掘之贝叶斯算法__C++实现.zip",这看起来是一个与决策树无关的...
总的来说,ID3算法是理解和学习决策树算法的一个重要起点,通过它的实现,我们可以了解决策树的基本构造原理和分类过程。在实际应用中,由于ID3对于连续型属性和缺失值的处理较为局限,后续的C4.5和CART算法对其进行...
决策树是一种常用的数据挖掘技术,用于分类...总结,ID3算法是决策树学习的基础,通过理解其原理并能用Java实现,可以为其他决策树算法的学习打下基础。在实际应用中,需要注意算法的局限性,并结合其他技术进行优化。
### C 实现决策树ID3算法 #### 一、概览 本文档旨在解析一个用C语言实现的决策树ID3算法的代码片段。决策树是一种常用的机器学习方法,广泛应用于分类与回归任务中。ID3(Iterative Dichotomiser 3)是决策树的一种...
通过这个项目,用户不仅可以了解ID3算法的基本原理,还可以亲手操作,感受决策树在实际问题中的应用,这对于理解和掌握数据挖掘技术是非常有帮助的。同时,由于使用了Java编程,开发者也可以根据需求对其进行扩展和...
决策树是一种广泛应用于机器学习和数据挖掘中的非线性模型,它通过一系列的特征测试将数据集分割成多个部分,最终形成一棵具有决策路径的树形结构。在本篇文章中,我们将深入理解决策树的基本模型、特征选择、生成...
【决策树】是一种重要的机器学习算法,常用于分类和回归任务。在生物数据挖掘领域,决策树被广泛应用于解析...通过对ID3算法的理解和实践,我们可以更好地掌握决策树的基本原理和应用方法,为实际问题提供解决方案。
决策树是一种常用的数据挖掘技术,用于分类和预测。在决策树构建过程中,ID3算法与C4.5算法是两种非常重要的算法,它们各有特点,适用于不同场景。 ### ID3算法 ID3(Iterative Dichotomiser 3)算法是由Ross ...