0805030115 梅超亮 数据挖掘 Apriori算法.docx

上传人:b****2 文档编号:17751643 上传时间:2023-08-03 格式:DOCX 页数:15 大小:29.25KB
下载 相关 举报
0805030115 梅超亮 数据挖掘 Apriori算法.docx_第1页
第1页 / 共15页
0805030115 梅超亮 数据挖掘 Apriori算法.docx_第2页
第2页 / 共15页
0805030115 梅超亮 数据挖掘 Apriori算法.docx_第3页
第3页 / 共15页
0805030115 梅超亮 数据挖掘 Apriori算法.docx_第4页
第4页 / 共15页
0805030115 梅超亮 数据挖掘 Apriori算法.docx_第5页
第5页 / 共15页
0805030115 梅超亮 数据挖掘 Apriori算法.docx_第6页
第6页 / 共15页
0805030115 梅超亮 数据挖掘 Apriori算法.docx_第7页
第7页 / 共15页
0805030115 梅超亮 数据挖掘 Apriori算法.docx_第8页
第8页 / 共15页
0805030115 梅超亮 数据挖掘 Apriori算法.docx_第9页
第9页 / 共15页
0805030115 梅超亮 数据挖掘 Apriori算法.docx_第10页
第10页 / 共15页
0805030115 梅超亮 数据挖掘 Apriori算法.docx_第11页
第11页 / 共15页
0805030115 梅超亮 数据挖掘 Apriori算法.docx_第12页
第12页 / 共15页
0805030115 梅超亮 数据挖掘 Apriori算法.docx_第13页
第13页 / 共15页
0805030115 梅超亮 数据挖掘 Apriori算法.docx_第14页
第14页 / 共15页
0805030115 梅超亮 数据挖掘 Apriori算法.docx_第15页
第15页 / 共15页
亲,该文档总共15页,全部预览完了,如果喜欢就下载吧!
下载资源
资源描述

0805030115 梅超亮 数据挖掘 Apriori算法.docx

《0805030115 梅超亮 数据挖掘 Apriori算法.docx》由会员分享,可在线阅读,更多相关《0805030115 梅超亮 数据挖掘 Apriori算法.docx(15页珍藏版)》请在冰点文库上搜索。

0805030115 梅超亮 数据挖掘 Apriori算法.docx

0805030115梅超亮数据挖掘Apriori算法

武汉工程大学

计算机科学与工程学院

《数据挖掘与知识发现》实验报告

专业班级

08智能1班

实验地点

计算机大楼419

学生学号

0805030115

指导教师

吕品

学生姓名

梅超亮

实验时间

2011-12-19

实验项目

实验2经典数据挖掘算法的实现

实验类别

操作性()验证性()设计性()综合性(√)其它()

实验目的及要求

1.进一步熟悉高级语言编程;

2.掌握使用Apriori算法从事物数据库中挖掘频繁项集的方法;掌握使用ID3算法对任意元组进行分类;掌握使用k-means算法给每一类帖上标签;

3.任选其中一个算法实现.

成绩评定表

类别

评分标准

分值

得分

合计

上机表现

积极出勤、遵守纪律

主动完成实验设计任务

30分

程序代码

比较规范、基本正确

功能达到实验要求

30分

实验报告

及时递交、填写规范

内容完整、体现收获

40分

说明:

评阅教师:

日期:

2011年月日

实验内容

1.算法思想

(1)首先遍历一次数据库,得到所有单元素的

 

 

最后的总结果:

 

2.源程序使用的数据结构

结构体Shop用来记录每个商店所拥有的商品名、该商店名

structShop

{

charTID[5];//商店Id

charGoods[5];//该商店所有的商品名

}AllElectronics[9];

结构体GoodNode记录链表的节点。

每个节点有以下内容:

商品名、该节点的支持度、下一个节点的地址。

structGoodNode

{

charGoods[10];

intsup;

structGoodNode*next;

};

结构体slistGoodV表示的是候选项目集的链表

structslistGoodV

{

structGoodNode*head;

structGoodNode*tail;

intlen;

}TALL;

3.源程序

#include

#include

#include

structShop

{

charTID[5];

charGoods[5];

}AllElectronics[9];

structGoodNode

{

charGoods[10];

intsup;

structGoodNode*next;

};

structslistGoodV

{

structGoodNode*head;

structGoodNode*tail;

intlen;

}TALL;

向候选项目集的链表中的尾部插入节点newnode

structGoodNode*AddTail(structGoodNode*newnode)

{

if(TALL.len==0)

{

TALL.head=newnode;

TALL.tail=newnode;

TALL.head->next=NULL;

TALL.tail->next=NULL;

}

else

{

TALL.tail->next=newnode;

TALL.tail->next->next=NULL;

TALL.tail=newnode;

}

TALL.len++;

returnTALL.head;

}

产生第一个链表

voidProduceListA()

{

chartmp[10];

structGoodNode*tem;

structGoodNode*flag,*flag2,*tail;

flag=TALL.head;

tail=TALL.tail;

while(flag!

=tail)

{

flag2=flag->next;

while(flag2!

=tail)

{

memset(tmp,0,10);

strcpy(tmp,flag->Goods);

strcat(tmp,flag2->Goods);

tem=(structGoodNode*)malloc(sizeof(structGoodNode));

strcpy(tem->Goods,tmp);

tem->sup=0;

AddTail(tem);

flag2=flag2->next;

}

memset(tmp,0,10);

strcpy(tmp,flag->Goods);

strcat(tmp,flag2->Goods);

tem=(structGoodNode*)malloc(sizeof(structGoodNode));

strcpy(tem->Goods,tmp);

tem->sup=0;

AddTail(tem);

flag=flag->next;

}

flag=TALL.head;

while(flag->sup!

=0)

{

TALL.head=TALL.head->next;

free(flag);

flag=TALL.head;

}

}

在前一个链表基础上产生下一个链表

voidProduceListB()

{

chartmp[10];

structGoodNode*tem;

structGoodNode*flag,*flag2,*tail;

flag=TALL.head;

tail=TALL.tail;

while(flag!

=tail)

{

flag2=flag->next;

while(flag2!

=tail)

{

if(flag->Goods[0]!

=flag2->Goods[0])

break;

memset(tmp,0,10);

strcpy(tmp,flag->Goods);

tmp[2]=flag2->Goods[1];

tmp[3]='\0';

tem=(structGoodNode*)malloc(sizeof(structGoodNode));

strcpy(tem->Goods,tmp);

tem->sup=0;

AddTail(tem);

flag2=flag2->next;

}

if(flag->Goods[0]==flag2->Goods[0])

{

memset(tmp,0,10);

strcpy(tmp,flag->Goods);

tmp[2]=flag2->Goods[1];

tmp[3]='\0';

tem=(structGoodNode*)malloc(sizeof(structGoodNode));

strcpy(tem->Goods,tmp);

tem->sup=0;

AddTail(tem);

}

flag=flag->next;

}

flag=TALL.head;

while(flag->sup!

=0)

{

TALL.head=TALL.head->next;

free(flag);

flag=TALL.head;

}

}

判断链表中的节点的商品名是否在某个商店中

intIfInItem(structShop*shop,structGoodNode*node)

{

inti=0;

intk=0;

intflag=0;

while(node->Goods[i]!

='\0')

{

k=0;

flag=0;

while(shop->Goods[k]!

='\0')

{

if(node->Goods[i]==shop->Goods[k])

{

flag=1;

break;

}

k++;

}

if(flag==0)

{

return0;

}

i++;

}

return1;

}

计算链表中每个节点的支持度

voidAddSup()

{

structGoodNode*tmp;

tmp=TALL.head;

inti=0;

intj;

while(tmp!

=NULL)

{

for(j=0;j<9;j++)

{

if(IfInItem(&AllElectronics[j],tmp)==1)

{

tmp->sup++;

}

}

tmp=tmp->next;

}

}

删除链表中的节点

voidDeleteNode(intk)//k为支持度

{

structGoodNode*tmp,*tmp2;

tmp=TALL.head;

while(tmp->next!

=NULL)

{

if(tmp->next->sup

{

tmp2=tmp->next;

tmp->next=tmp2->next;

free(tmp2);

}

else

tmp=tmp->next;

TALL.len--;

}

if(TALL.head->sup

{

tmp=TALL.head;

TALL.head=TALL.head->next;

free(tmp);

TALL.len--;

}

}

boolJudgeSame(char*temp)

{

structGoodNode*tmp;

tmp=TALL.head;

while(tmp!

=NULL)

{

while(strcmp(tmp->Goods,temp)==0)

{

tmp->sup++;

returntrue;

}

tmp=tmp->next;

}

returnfalse;

}

打印链表

voidProduceList()

{

inti;

intj;

intk=0;

chartmp[10];

structGoodNode*tem;

for(i=0;i<9;i++)

{

for(j=0;j<4;j++)

{

memset(tmp,0,10);

k=0;

if(AllElectronics[i].Goods[j]=='\0')

break;

tmp[k++]=AllElectronics[i].Goods[j];

tmp[k++]='\0';

if(JudgeSame(tmp)==true)

continue;

tem=(structGoodNode*)malloc(sizeof(structGoodNode));

strcpy(tem->Goods,tmp);

tem->sup=0;

AddTail(tem);

}

}

}

voidprintTall()

{

structGoodNode*tmp;

tmp=TALL.head;

while(tmp!

=NULL)

{

printf("%s\t%d\n",tmp->Goods,tmp->sup);

tmp=tmp->next;

}

}

初始化商店的商品信息

voidInitShop()

{

strcpy(AllElectronics[0].TID,"T100");

strcpy(AllElectronics[0].Goods,"ABE");

strcpy(AllElectronics[1].TID,"T200");

strcpy(AllElectronics[1].Goods,"BD");

strcpy(AllElectronics[2].TID,"T300");

strcpy(AllElectronics[2].Goods,"BC");

strcpy(AllElectronics[3].TID,"T400");

strcpy(AllElectronics[3].Goods,"ABD");

strcpy(AllElectronics[4].TID,"T500");

strcpy(AllElectronics[4].Goods,"AC");

strcpy(AllElectronics[5].TID,"T600");

strcpy(AllElectronics[5].Goods,"BC");

strcpy(AllElectronics[6].TID,"T700");

strcpy(AllElectronics[6].Goods,"AC");

strcpy(AllElectronics[7].TID,"T800");

strcpy(AllElectronics[7].Goods,"ABCE");

strcpy(AllElectronics[8].TID,"T900");

strcpy(AllElectronics[8].Goods,"ABC");

}

intmain()

{

TALL.head=NULL;

TALL.tail=NULL;

TALL.len=0;

InitShop();

inti,j=0;

printf("商店信息\n");

printf("商店名\t商品\n");

for(i=0;i<9;i++)

{

printf("%s\t",AllElectronics[i].TID);

 

printf("%s\t",AllElectronics[i].Goods);

printf("\n");

}

printf("第一次产生频繁项集\n");

printf("项集\t支持度\n");

ProduceList();

printTall();

printf("剔除支持度小于\n");

DeleteNode

(2);

printTall();

printf("第二次产生频繁项集\n");

printf("项集\t支持度\n");

ProduceListA();

AddSup();

printTall();

printf("第三次产生频繁项集\n");

printf("项集\t支持度\n");

ProduceListB();

AddSup();

printTall();

return0;

}

实验总结

在这次实验中的难点是:

关联规则挖掘的第二阶段——产生关联规则(AssociationRules)。

从高频项目组产生关联规则,是利用前一步骤的高频k-项目组来产生规则,在最小信赖度(MinimumConfidence)的条件门槛下,经由高频k-项目组{A,B}所产生的规则AB,其信赖度可经由公式求得,若数据结构设置的不好,后面的计算量将不是局部的改变,而是伴随后面所有的候选项目集。

所以我的想法是纵方向设置一个项目集链表,横方向是字符串型的数组。

后面的项目集有前一个的候选项目集产生,所以链表会不断变化,最后就得出了大项目集。

这次实验花费了很长时间,也学到了很多知识,很感谢吕品老师的悉心指导和同学们的热情帮助,让我按时完成了这次实验。

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 自然科学 > 物理

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2