-
大小: 2.8MB文件類型: .zip金幣: 2下載: 0 次發(fā)布日期: 2023-09-20
- 語言: 其他
- 標簽:
資源簡介
中科大數(shù)據(jù)挖掘作業(yè) 建立決策樹

代碼片段和文件信息
#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;//屬性的個數(shù)??
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?<“決策樹以廣義表形式輸出如下:“?< treelists(T);?
cout?<}
void?treelists(tree?T)//以廣義表的形式輸出樹??
{
tree?p;
if?(!T)
return;
cout?<“{“?<weight?<“}“;
cout?<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
評論
共有 條評論