《数据挖掘实验报告-数据预处理》由会员分享,可在线阅读,更多相关《数据挖掘实验报告-数据预处理(5页珍藏版)》请在金锄头文库上搜索。
1、数据挖掘实验报告(一)数据预处理姓名:李圣杰班级:计算机1304学号:1311610602 一、实验目的1.学习均值平滑,中值平滑,边界值平滑的基本原理2.掌握链表的使用方法3.掌握文件读取的方法二、实验设备 PC一台,dev-c+5.11三、实验内容 数据平滑 假定用于分析的数据包含属性age。数据元组中age的值如下(按递增序):13, 15, 16, 16, 19, 20, 20, 21, 22, 22, 25, 25, 25, 25, 30, 33, 33, 35, 35, 35, 35, 36, 40, 45, 46, 52, 70。使用你所熟悉的程序设计语言进行编程,实现如下功能(
2、要求程序具有通用性):(a) 使用按箱平均值平滑法对以上数据进行平滑,箱的深度为3。(b) 使用按箱中值平滑法对以上数据进行平滑,箱的深度为3。(c) 使用按箱边界值平滑法对以上数据进行平滑,箱的深度为3。四、实验原理 使用c语言,对数据文件进行读取,存入带头节点的指针链表中,同时计数,均值求三个数的平均值,中值求中间的一个数的值,边界值将中间的数转换为离边界较近的边界值五、实验步骤代码#include #include #include #define DEEP 3#define DATAFILE data.txt#define VPT 10/定义结构体typedef struct chai
3、nint num;struct chain *next;* data;/定义全局变量data head,p,q;FILE *fp;int num,sum,count=0;int i,j;int *box;voidmean();voidmedain();voidboundary();int main ()/定义头指针head=(data)malloc(sizeof(struct chain);head-next=NULL; /*打开文件*/fp=fopen(DATAFILE,r); if(!fp)exit(0);p=head;while(!feof(fp)q=(data)malloc(sizeo
4、f(struct chain);q-next=NULL;fscanf(fp,%d,&q-num); /*读一个数据*/p-next=q;p=q;count+; /* 关闭文件 */fclose(fp);/输出printf(源数据为:n);printf(共%d箱%d个数据n,count/DEEP,count);p=head-next;count=1;num=1;while(p!=NULL)if(count=1)printf(箱%d:,num);if(count=DEEP)printf(%dn,p-num);num+;count=1;elseprintf(%d ,p-num);count+;p=p
5、-next;mean();medain();boundary();scanf(%d,&i);return 0;/均值void mean()printf(均值平滑后为:);box=(int *)malloc(sizeof(int)*num);p=head-next;count=1;num=0;sum=0;while(p!=NULL)if(count=DEEP)count=1;sum=sum+p-num;boxnum=sum/DEEP;sum=0;num+;elsesum=sum+p-num;count+;p=p-next;for (i=0;inum;i+)printf(n箱%d:,i+1);fo
6、r (j=0;jnext;printf(n离群值为:);while(p!=NULL)for(i=0;inum;i+)for (j=0;jnum-boxi)(int)VPT)printf(n箱%d:,i+1); printf(%d ,p-num); p=p-next;/中值void medain()printf(n中值平滑后为:);p=head-next;count=1;num=0;int mid;while(p!=NULL)if(count=DEEP)boxnum=sum;count=1;num+;else if(count=DEEP/2|count=DEEP/2+1)if(DEEP%2)if
7、(count=DEEP/2+1)sum=p-num;elseif(count=DEEP/2+1)sum=(p-num+mid)/2;elsemid=p-num;count+;p=p-next;for (i=0;inum;i+)printf(n箱%d:,i+1);for (j=0;jnext;count=1;box=(int *)malloc(sizeof(int)*num*2);num=0;while(p!=NULL)if(count=DEEP)box2*num+1=p-num;count=1;num+;else if(count=1) box2*num=p-num; count+;p=p-n
8、ext;p=head-next;count=1;num=0;while(p!=NULL)if(count=1)printf(箱%d:,num);if(p-num-box2*num)(box2*num+1-p-num)printf(%d ,box2*num+1);elseprintf(%d ,box2*num);if(count=DEEP)printf(n);count=0;num+;count+;p=p-next;实验数据文件:data.txt用空格分开13 15 16 16 19 20 20 21 22 22 25 25 25 25 30 33 33 35 35 35 35 36 40 45 46 52 70六、结果截图