聚类分析需求分析书.docx
- 文档编号:27215790
- 上传时间:2023-06-28
- 格式:DOCX
- 页数:20
- 大小:420.97KB
聚类分析需求分析书.docx
《聚类分析需求分析书.docx》由会员分享,可在线阅读,更多相关《聚类分析需求分析书.docx(20页珍藏版)》请在冰豆网上搜索。
聚类分析需求分析书
聚类分析需求分析书
引言
聚类(Cluster)分析是由若干模式(Pattern)组成的,通常,模式是一个度量(Measurement)的向量,或者是多维空间中的一个点。
聚类分析以相似性为基础,在一个聚类中的模式之间比不在同一聚类中的模式之间具有更多的相似性。
编写目的
聚类的用途是很广泛的。
它作为数据挖掘中的一个模块,可以作为一个单独的工具以发现数据库中分布的一些深层的信息,并且概括出每一类的特点,或者把注意力放在某一个特定的类上以作进一步的分析;并且,聚类分析也可以作为数据挖掘算法中其他分析算法的一个预处理步骤。
聚类分析的算法可以分为划分法(PartitioningMethods)、层次法(HierarchicalMethods)、基于密度的方法(density-basedmethods)、基于网格的方法(grid-basedmethods)、基于模型的方法(Model-BasedMethods)。
背景
1.本系统名称:
聚类分析应用系统
2.本项目的任务是对大数据进行聚类分析,便于管理者进行决策
1.任务概述
◆实现界面选择化,可以选择读取数据的路径,输出数据的路径类型
◆可以对输出的数据进行保存
◆出现差错时进行相应的提示
2.用户特点
用户具有一定的电脑应用基础,具有一定的计算机操作知识,能正确选择要输入的数据路径,及输出的数据路径及类型
3.建设思路
应用java技术开发,完成基本的人机交互;实现数据的处理、调用。
4.算法描述
◆K-means算法:
然后将事先输入的n个数据对象划分为k个聚类以便使得所获得的聚类满足:
同一聚类中的对象相似度较高;而不同聚类中的对象相似度较小。
聚类相似度是利用各聚类中对象的均值所获得一个“中心对象”(引力中心)来进行计算的。
◆K-medoids算法:
算法的工作过程说明如下:
首先从n个数据对象任意选择k个对象作为初始聚类中心;而对于所剩下其它对象,则根据它们与这些聚类中心的相似度(距离),分别将它们分配给与其最相似的(聚类中心所代表的)聚类;然后再计算每个所获新聚类的聚类中心(该聚类中所有对象的均值);不断重复这一过程直到标准测度函数开始收敛为止。
一般都采用均方差作为标准测度函数.k个聚类具有以下特点:
各聚类本身尽可能的紧凑,而各聚类之间尽可能的分开。
5.系统功能设计
5.1总体功能设计
5.2总业务流图
6.算法流程图
◆K-MEANS流程图
◆K-MEDOIDS流程图
7.假定约束
经费有限,开发时间紧迫,使用JAVA进行程序的开发
8.功能描述
8.1<功能块1>
【功能名称】
导入文件
【功能描述】
从外存导入数据文件。
【业务规则和操作说明】
用户点击系统界面上的“导入数据”按钮,出现文件选择器界面,选择需要导入的文件,点击“打开”按钮。
【算法】
publicvoiddaoinIFrame(){
JFileChooserchooser=newJFileChooser(newFile("F:
\\文档\\实习"));
FileNameExtensionFilterfilter=newFileNameExtensionFilter("文本文件","txt","doc");
chooser.setFileFilter(filter);
intoption=chooser.showOpenDialog(this);
if(option==JFileChooser.APPROVE_OPTION){
file=chooser.getSelectedFile();
try{
BufferedReaderbis=newBufferedReader(newFileReader(file));
intc;
sb=newStringBuffer();
while((c=bis.read())!
=-1){
sb.append((char)c);
}
Text1.setText(""+sb.toString());
bis.close();
}catch(FileNotFoundExceptione1){
e1.printStackTrace();
}catch(IOExceptione2){
e2.printStackTrace();
}
String[]rowData=sb.toString().split("\n");
introw=rowData.length;
String[][]colData=newString[row][];
for(inti=0;i colData[i]=rowData[i].split("{1,}"); } intcol=colData[0].length; data=newdouble[row][col]; for(inti=0;i for(intj=0;j try{ data[i][j]=Double.parseDouble(colData[i][j]); //System.out.print(data[i][j]+""); }catch(Exceptione1){ JOptionPane.showMessageDialog(null,"数据输入有误! 请修正之后再导入。 "); return; } } } } } 8.2<功能块2> 【功能名称】 导出文件 【功能描述】 将程序运行结果导出文件。 【业务规则和操作说明】 程序运行结束,用户点击系统界面上的“保存结果”按钮,直接生成元数据文件名与算法相应的文件(*.txt)。 【算法】 publicvoiddaooutIFrame(){ if(Text1.getText()==null||Text1.getText().equals("")){ JOptionPane.showMessageDialog(null,"请导入源文件"); return; } if(Text2.getText()==null||Text2.getText().equals("")){ JOptionPane.showMessageDialog(null,"请输入k值"); return; } if(Option1.isSelected()){ try{ Filefile1=newFile(file.getPath().substring(0,file.getPath().lastIndexOf("."))+"--means_result.txt"); daochu(file1); }catch(FileNotFoundExceptione){ e.printStackTrace(); }catch(IOExceptione){ e.printStackTrace(); }catch(NullPointerExceptione){ Filefile1=newFile("F: \\文档\\实习\\result-medoids_result.txt"); try{ daochu(file1); }catch(IOExceptione1){ e1.printStackTrace(); } } } else{ try{ Filefile1=newFile(file.getPath().substring(0,file.getPath().lastIndexOf("."))+"--medoids_result.txt"); daochu(file1); }catch(FileNotFoundExceptione){ e.printStackTrace(); }catch(IOExceptione){ e.printStackTrace(); }catch(NullPointerExceptione){ Filefile1=newFile("F: \\文档\\实习\\result--means_result.txt"); try{ daochu(file1); }catch(IOExceptione1){ e1.printStackTrace(); } } } } 8.3<功能块3> 【功能名称】 K-Means算法。 【功能描述】 将用户导入的文件数据用K-Meams算法运行处理。 。 【业务规则和操作说明】 用户选择系统界面上的“K-Meams”单选按钮,然后输入分组数,点击的“确定”按钮。 【算法】 publicvoiddeterIFrame(){ if(Text1.getText()==null||Text1.getText().equals("")){ JOptionPane.showMessageDialog(null,"请导入源文件"); return; } if(data==null){ JOptionPane.showMessageDialog(null,"请输入数据"); return; } if(Text2.getText()==null||Text2.getText().equals("")){ JOptionPane.showMessageDialog(null,"请输入k值"); return; } k=Integer.parseInt(Text2.getText()); if(Option1.isSelected()){ means=newrunK_means(data,k); Text1.setText(means.stringBuffer()); } if(Option2.isSelected()){ medoids=newrunK_medoids(data,k); Text1.setText(medoids.stringBuffer()); } } 8.4<功能块4> 【功能名称】 K-Medoids算法。 【功能描述】 将用户导入的文件数据用K-Medoids算法运行处理。 。 【业务规则和操作说明】 用户选择系统界面上的“K-Medoids”单选按钮,然后输入分组数,点击的“确定”按钮。 【算法】 与8.3算法一致 9.数据处理 9.1K-Means算法处理 1)选取数据的初始中心点的坐标(firstCentre()) 2)计算所有点到中心点的距离,并生成距离矩阵(distance(double[][]centre,double[][]data)) 3)标记处个点到哪个中心距离最小,得出分类向量(ouType()) 4)遍历分类向量,得出每个类别的个数(process()) 5)利用各类数据加和取平均,得出新的中心坐标(findMeansNcentre()) 6)判断新旧中心坐标是否一致,若不一致新中心坐标取代就中心坐标(isequelMatrix(double[][]matrix1,double[][]matrix2)),继续2——6;若两者一致,则输出计算结果(printout()) 9.1K-Medoids算法处理 1)选取数据的初始中心点的坐标(firstCentre()) 2)计算所有点到中心点的距离,并生成距离矩阵(distance(double[][]centre,double[][]data)) 3)标记处个点到哪个中心距离最小,得出分类向量(ouType()) 4)遍历分类向量,得出每个类别的个数(process()) 5)取出某类数据,得出各点之间的距离,并找出距离和的最小值,最小值所对应坐标即为新的中心坐标(findMedoidsNcentre()) 6)判断新旧中心坐标是否一致,若不一致新中心坐标取代就中心坐标(isequelMatrix(double[][]matrix1,double[][]matrix2)),继续2——6;若两者一致,则输出计算结果(printout()) 【算法】 ◆K-means publicrunK_means(double[][]dat,intkk){ data=dat; k=kk; row=data.length; col=data[0].length; centre=newdouble[k][col]; Ncentre=newdouble[k][col]; type=newint[row]; firstCentre(); do{ times++; process(); findMeansNcentre(); }while(! isequelMatrix(centre,Ncentre)); printout(); } ◆K-medoids publicrunK_medoids(double[][]dat,intkk){ data=dat; k=kk; row=data.length; col=data[0].length; centre=newdouble[k][col]; Ncentre=newdouble[k][col]; firstCentre(); do{ times++; process(); findMedoidsNcentre(); }while(! isequelMatrix(centre,Ncentre)); printout(); } 9.3具体方法 ◆firstCentre(); publicvoidfirstCentre(){ for(inti=0;i for(intj=0;j centre[i][j]=data[i][j]; } } ◆ouTpye(); publicvoidouType(){ distance(centre,data); type=newint[row]; for(intj=0;j doublemin=dis[0][j]; for(inti=1;i if(dis[i][j]<=min){ min=dis[i][j]; type[j]=i; } } } ◆Process(); publicvoidprocess(){ outType(); count=newint[k]; for(inti=0;i intm=type[i]; count[m]++; } } ◆findMeansNcentre(); publicvoidfindMeansNcentre(){ double[][]Nicentre=newdouble[k][col]; Ncentre=Nicentre; for(inti=0;i intm=type[i]; for(intj=0;j Ncentre[m][j]+=data[i][j]/count[m]; } } ◆findMedoidsNcentre(); publicvoidfindMedoidsNcentre(){ int[]Ncount=newint[k];//zubiexiabiao double[][]Ndata=newdouble[row][col];//zhuanhuanhoudejuzhen for(inti=1;i Ncount[i]=Ncount[i-1]+count[i-1]; } for(inti=0;i intm=type[i]; intn=Ncount[m]; for(intj=0;j Ndata[n][j]=data[i][j]; Ncount[m]++; } for(inti=0;i Ncount[i]=Ncount[i]-count[i]; } for(intm=0;m double[][]Nidata=newdouble[count[m]][col]; for(inti=0;i for(intj=0;j Nidata[i][j]=Ndata[i+Ncount[m]][j]; } //Ncentre[m]=findNcentre(); distance(Nidata,Nidata); double[]addis=newdouble[count[m]]; for(inti=0;i for(intj=0;j addis[i]+=dis[i][j]; } doublemin=addis[0]; intorder=0; for(inti=0;i if(addis[i] min=addis[i]; order=i; } Ncentre[m]=Nidata[order]; } } ◆isequelMatirx(); publicbooleanisequelMatrix(double[][]matrix1,double[][]matrix2){ booleanresult=true; if((matrix1.length==matrix2.length)&&(matrix1[0].length==matrix2[0].length)){ for(inti=0;i for(intj=0;j if(matrix1[i][j]! =matrix2[i][j]) result=false; matrix1[i][j]=matrix2[i][j]; } } else{ result=false; } returnresult; } ◆Printout(); publicvoidprintout(){ sb=newStringBuffer(); sb.append("寻找中心的次数为: "+times).append("\n"); for(inti=0;i intorder=i+1; sb.append("第"+order+"中心点坐标为: ").append("\n"); for(intj=0;j sb.append(centre[i][j]+""); } sb.append("\n"); sb.append("对应的点为: ").append("\n"); for(intim=0;im if(type[im]==i){ sb.append("["+im+"]"); for(intjm=0;jm sb.append(data[im][jm]+""); } sb.append("\n"); } } sb.append("\n"); } sb.append("\n"); }
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 聚类分析 需求 分析