• 大小: 262KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-06-07
  • 语言: 其他
  • 标签: ID3算法  决策树  

资源简介

一个简单的ID3决策树算法实现,但是很使用。简单易懂。

资源截图

代码片段和文件信息

#include
#include
#include
typedef struct info {
char name[20];
char sex[10];
float hight;
char clas[10];
}infor;
  void main()
  {   
  int i;
  cout<<“请输入人数:“< cin>>i;
infor *p;
p=new infor[i];
        for(int j=1;j<=i;j++)
{
       cout<<“请输入第“<           cin>>p[j].name;
   cin>>p[j].sex;
   cin>>p[j].hight;
   cin>>p[j].clas;
}
cout<<“C4.5算法:“<     int countmale=0countfemale=0countclasshort=0countclasmidium=0countclashigh=0;
         for( j=1;j<=i;j++)
 {
 if(!strcmp(p[j].sex“female“)||!strcmp(p[j].sex“女“)){countfemale++;}
 else if(!strcmp(p[j].sex“male“)||!strcmp(p[j].sex“男“)){countmale++;}
       if(!strcmp(p[j].clas“short“)||!strcmp(p[j].clas“矮“)) countclasshort++;
       else if(!strcmp(p[j].clas“midium“)||!strcmp(p[j].clas“中“))  countclasmidium++;
              else if(!strcmp(p[j].clas“high“)||!strcmp(p[j].clas“高“))countclashigh++;
 }
 
   double initHinitshortHinitmidiumHinithighH;
        if(countclasshort==0) initshortH=0;
              else initshortH=((double)(countclasshort)/(countclasshort+countclasmidium+countclashigh))*log10((countclasshort+countclasmidium+countclashigh)/(double)(countclasshort));
            if(countclasmidium==0) initmidiumH=0;
       else initmidiumH=((double)(countclasmidium)/(countclasshort+countclasmidium+countclashigh))*log10((countclasshort+countclasmidium+countclashigh)/(double)(countclasmidium));
                     if(countclashigh==0) inithighH=0;
    else inithighH=((double)(countclashigh)/(countclasshort+countclasmidium+countclashigh))*log10((countclasshort+countclasmidium+countclashigh)/(double)(countclashigh));
              initH=initshortH+initmidiumH+inithighH;
  double  femaleHmaleHfemaleshortHfemalemidiumHfemalehighHmaleshortHmalemidiumHmalehighH;
    int sexshort=0sexmidium=0sexhigh=0;
    for(j=1;j<=i;j++)
{
  if(!strcmp(p[j].sex“female“)||!strcmp(p[j].sex“女“))
   {
  if(!strcmp(p[j].clas“short“)||!strcmp(p[j].clas“矮“)) {sexshort++;}
    else if(!strcmp(p[j].clas“midium“)||!strcmp(p[j].clas“中“))  {sexmidium++;}
     else if(!strcmp(p[j].clas“high“)||!strcmp(p[j].clas“高“)) { sexhigh++;}
   }
}
  if(sexshort==0) femaleshortH=0;
   else femaleshortH=((double)(sexshort)/countfemale)*log10(countfemale/(double)(sexshort));
      if(sexmidium==0) femalemidiumH=0;
     else femalemidiumH=((double)(sexmidium)/countfemale)*log10(countfemale/(double)(sexmidium));
                            if(sexhigh==0) femalehighH=0;
  else femalehighH=((double)(sexhigh)/countfemale)*log10(countfemale/(double)(sexhigh));
femaleH=femaleshortH+femalemidiumH+femalehighH;
sexshort=0sexmidium=0sexhigh=0;
    for(j=1;j<=i;j++)
{
if(!strcmp(p[j].sex“male“)||!strcmp(p[j].sex“男“))
{
if(!strcmp(p[

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件     245842  2010-05-04 20:45  ID3\Debug\file.exe

     文件     279188  2010-05-04 20:45  ID3\Debug\file.ilk

     文件      23934  2010-05-04 20:45  ID3\Debug\file.obj

     文件     264888  2010-05-04 20:45  ID3\Debug\file.pch

     文件     435200  2010-05-04 20:45  ID3\Debug\file.pdb

     文件      41984  2010-05-04 20:45  ID3\Debug\vc60.idb

     文件      61440  2010-05-04 20:45  ID3\Debug\vc60.pdb

     文件      12527  2009-09-04 10:51  ID3\file.cpp

     文件       3377  2010-05-04 20:45  ID3\file.dsp

     文件        533  2010-05-04 20:46  ID3\file.dsw

     文件      33792  2010-05-04 20:46  ID3\file.ncb

     文件      48640  2010-05-04 20:46  ID3\file.opt

     文件       1132  2010-05-04 20:45  ID3\file.plg

     目录          0  2010-05-04 20:45  ID3\Debug

     目录          0  2010-05-04 20:46  ID3

----------- ---------  ---------- -----  ----

              1452477                    15


评论

共有 条评论