资源简介
中科大数据挖掘作业 建立决策树
代码片段和文件信息
#include
#include
#include
#include
using namespace std;
typedef struct TNode
{
char data[15];
char weight[15];
TNode * firstchild *brother;
}*tree;
typedef struct LNode
{
char weather[15];
char temperature[15];
char humidity[15];
char wind[15];
char sport[5];
LNode *next;
}*link;
typedef struct AttrNode
{
char attributes[15];//属性
int attr_Num;//属性的个数
AttrNode *next;
}*Attributes;
char * Examples[14][5] = { //样本来自书上P48的表格。
“Sunny“ “Hot“ “High“ “Weak“ “No“
“Sunny“ “Hot“ “High“ “Strong“ “No“
“Cloudy“ “Hot“ “High“ “Weak“ “Yes“
“Rain“ “Mild“ “High“ “Weak“ “Yes“
“Rain“ “Cool“ “Normal“ “Weak“ “Yes“
“Rain“ “Cool“ “Normal“ “Strong“ “No“
“Cloudy“ “Cool“ “Normal“ “Strong“ “Yes“
“Sunny“ “Mild“ “High“ “Weak“ “No“
“Sunny“ “Cool“ “Normal“ “Weak“ “Yes“
“Rain“ “Mild“ “Normal“ “Weak“ “Yes“
“Sunny“ “Mild“ “Normal“ “Strong“ “Yes“
“Cloudy“ “Mild“ “Normal“ “Strong“ “Yes“
“Cloudy“ “Hot“ “Normal“ “Weak“ “Yes“
“Rain“ “Mild“ “High“ “Strong“ “No“
};
char * Attributes_kind[4] = { “weather“ “temperature“ “humidity“ “wind“ };
int Attr_kind[4] = { 3 3 2 2 };
char * weather_kind[3] = { “Sunny“ “Cloudy“ “Rain“ };
char * temperature_kind[3] = { “Hot“ “Mild“ “Cool“ };
char * humidity_kind[2] = { “High“ “Normal“ };
char * wind_kind[2] = { “Weak“ “Strong“ };
void treelists(tree T);
void InitAttr(Attributes &attr_link char * Attributes_kind[] int Attr_kind[]);
void Initlink(link &L char * Examples[][5]);
void ID3(tree &T link L link Target_Attr Attributes attr);
void PN_Num(link L int &positve int &negative);
void ID(tree & T link L link Target_Attr Attributes attr);
int count = 0;
void main()
{
link LL p;
Attributes attr_L q;
tree T;
T = new TNode;
T->firstchild = T->brother = NULL;
strcpy_s(T->weight“root“);
strcpy_s(T->data““);
attr_L = new AttrNode;
attr_L->next = NULL;
LL = new LNode;
LL->next = NULL;
Initlink(LL Examples);//原始的样本链表
InitAttr(attr_L Attributes_kind Attr_kind);
ID3(T LL NULL attr_L);
cout << “决策树以广义表形式输出如下:“ << endl;
treelists(T);
cout << endl;
}
void treelists(tree T)//以广义表的形式输出树
{
tree p;
if (!T)
return;
cout << “{“ << T->weight << “}“;
cout << T->data;
p = T->firstchild;
if (p)
{
cout << “(“;
while (p)
{
treelists(p);
p = p->brother;
if (p)cout << ‘‘;
}
cout << “)“;
}
}
void InitAttr(Attributes &attr_link char * Attributes_kind[] int Attr_kind[])//属性链表的初始化
{
Attributes p;
for (int i = 0; i < 4; i++)
{
p = new AttrNode;
p->next = NULL;
strcpy_s(p->attributes Attributes_kind[i]);
p->attr_Num = Attr_kind[i];
p->next = attr_link->next;
attr_link->next = p;
}
}
void Initlink(link &LL char * Examples[][5])//样本链表的初始化
{
link p;
for (int i = 0; i < 14; i++)
{
p = new LNode;
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2016-03-08 21:42 ID3\
目录 0 2016-03-08 19:17 ID3\Debug\
文件 79872 2016-03-08 21:42 ID3\Debug\ID3.exe
文件 801480 2016-03-08 21:42 ID3\Debug\ID3.ilk
文件 1208320 2016-03-08 21:42 ID3\Debug\ID3.pdb
目录 0 2016-03-08 21:42 ID3\ID3\
文件 7798784 2016-03-08 21:42 ID3\ID3.sdf
文件 955 2016-03-08 01:12 ID3\ID3.sln
文件 22528 2016-03-08 21:42 ID3\ID3.v12.suo
目录 0 2016-03-08 21:42 ID3\ID3\Debug\
文件 1713 2016-03-08 21:42 ID3\ID3\Debug\ID3.log
目录 0 2016-03-08 21:42 ID3\ID3\Debug\ID3.tlog\
文件 708 2016-03-08 21:42 ID3\ID3\Debug\ID3.tlog\cl.command.1.tlog
文件 12596 2016-03-08 21:42 ID3\ID3\Debug\ID3.tlog\CL.read.1.tlog
文件 588 2016-03-08 21:42 ID3\ID3\Debug\ID3.tlog\CL.write.1.tlog
文件 188 2016-03-08 21:42 ID3\ID3\Debug\ID3.tlog\ID3.lastbuildstate
文件 1258 2016-03-08 21:42 ID3\ID3\Debug\ID3.tlog\li
文件 2624 2016-03-08 21:42 ID3\ID3\Debug\ID3.tlog\li
文件 562 2016-03-08 21:42 ID3\ID3\Debug\ID3.tlog\li
文件 156238 2016-03-08 21:42 ID3\ID3\Debug\Source.obj
文件 281600 2016-03-08 21:42 ID3\ID3\Debug\vc120.idb
文件 364544 2016-03-08 21:42 ID3\ID3\Debug\vc120.pdb
文件 4082 2016-03-08 01:13 ID3\ID3\ID3.vcxproj
文件 958 2016-03-08 18:57 ID3\ID3\ID3.vcxproj.filters
文件 10976 2016-03-08 21:42 ID3\ID3\Source.cpp
- 上一篇:基于机器视觉的水果外部品质检测系统
- 下一篇:mui github官方组件包
评论
共有 条评论