1数据挖掘实验报告(一)数据预处理姓名:李圣杰班级:计算机1304学号:13116106022一、实验目的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。使用你所熟悉的程序设计语言进行编程,实现如下功能(要求程序具有通用性):(a)使用按箱平均值平滑法对以上数据进行平滑,箱的深度为3。(b)使用按箱中值平滑法对以上数据进行平滑,箱的深度为3。(c)使用按箱边界值平滑法对以上数据进行平滑,箱的深度为3。四、实验原理使用c语言,对数据文件进行读取,存入带头节点的指针链表中,同时计数,均值求三个数的平均值,中值求中间的一个数的值,边界值将中间的数转换为离边界较近的边界值五、实验步骤代码#includestdio.h#includestdlib.h#includemath.h#defineDEEP3#defineDATAFILEdata.txt#defineVPT10//定义结构体typedefstructchain{intnum;structchain*next;}*data;//定义全局变量datahead,p,q;FILE*fp;intnum,sum,count=0;inti,j;int*box;voidmean();voidmedain();voidboundary();intmain(){//定义头指针head=(data)malloc(sizeof(structchain));head-next=NULL;/*打开文件*/fp=fopen(DATAFILE,r);if(!fp)exit(0);p=head;while(!feof(fp)){3q=(data)malloc(sizeof(structchain));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(%d\n,p-num);num++;count=1;}else{printf(%d,p-num);count++;}p=p-next;}mean();medain();boundary();scanf(%d,&i);return0;}//均值voidmean(){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;box[num]=sum/DEEP;sum=0;num++;}else{sum=sum+p-num;count++;}p=p-next;}for(i=0;inum;i++){printf(\n箱%d:,i+1);for(j=0;jDEEP;j++)printf(%d,box[i]);}p=head-next;printf(\n离群值为:);while(p!=NULL){for(i=0;inum;i++){for(j=0;jDEEP;j++){if(abs(p-num-box[i])(int)VPT){printf(\n箱%d:,i+1);printf(%d,p-num);}p=p-next;}}}}//中值voidmedain(){printf(\n中值平滑后为:);4p=head-next;count=1;num=0;intmid;while(p!=NULL){if(count==DEEP){box[num]=sum;count=1;num++;}else{if(count==DEEP/2||count==DEEP/2+1)if(DEEP%2){if(count==DEEP/2+1)sum=p-num;}else{if(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;jDEEP;j++)printf(%d,box[i]);}}//边界值voidboundary(){printf(\n边界值平滑后为:\n);p=head-next;count=1;box=(int*)malloc(sizeof(int)*num*2);num=0;while(p!=NULL){if(count==DEEP){box[2*num+1]=p-num;count=1;num++;}else{if(count==1){box[2*num]=p-num;}count++;}p=p-next;}p=head-next;count=1;num=0;while(p!=NULL){if(count==1)printf(箱%d:,num);if((p-num-box[2*num])(box[2*num+1]-p-num)){printf(%d,box[2*num+1]);}elseprintf(%d,box[2*num]);if(count==DEEP){printf(\n);count=0;num++;}count++;p=p-next;}}实验数据文件:data.txt用空格分开1315161619202021222225252525303333353535353640454652705六、结果截图