1一、设计目的1.更深的了解关联规则挖掘的原理和算法。2.能将数据挖掘知识与计算机编程相结合,编写出合理的程序。3.深入了解Apriori算法。二、设计要求1.能设置支持度,置信度和挖掘深度。2.能输入或导入待挖掘的相关记录。3.程序无BUG,没有原理性错误。三、设计实现流程图2四、实现环境1.系统:Windows7sp1X862.Netbeans7.1.123.JDK7.0五、实现结果1.界面:32.输入待挖掘项目:43.输入支持度,置信度和挖掘深度4.进行分析5六、设计小结通过这次的数据挖掘课程设计,6附录:主要代码Apriori算法:packageapriori;importjava.util.*;publicclassApriori{privatedoubleminSupport;//最小支持度privatedoubleminConfidence;//最小置信度privateMapcontainer;//交易数据容器privateinttotalSize;//样品数据条数privateListcanditateSetList=newArrayList();//候选集链表privateListfrequentSetList=newArrayList();//频繁集链表privateListmaxFrequentSetList=newArrayList();//最大频繁集privateintmaxDeep=-1;privateintcurDeep=0;privatebooleanisStop=false;privateSetelementSet=newTreeSet();privateListruleList=newArrayList();//设置挖掘深度,如果为-1,表明直到不产生新的频繁集才停止挖掘publicvoidsetDeep(intk){this.maxDeep=k;}privatedoublegetMinConfidence(){returnminConfidence;}publicvoidsetMinConfidence(doubleminConfidence){this.minConfidence=minConfidence;}privatedoublegetMinSupport(){returnminSupport;}publicvoidsetMinSupport(doubleminSupport){this.minSupport=minSupport;}7privateMapgetContainer(){returncontainer;}publicvoidsetContainer(TransactionContainertransactionContainer){this.container=transactionContainer.getContainer();this.totalSize=this.container.size();System.out.println(,,,,,,,,,,,,,,,,,,,,,,,,,,,,);System.out.println(totalSize);}privatebooleanisStop(){returnthis.isStop||(maxDeep0&&curDeep==maxDeep);}privatevoidstopAnalyse(){this.isStop=true;}/***根据最小支持度,最小自信度,样品数据进行数据分析**/publicvoidanalyse(){//计算候选集、频繁集this.makeCanditateSet1();this.makeFrequentSet1();while(!isStop()){this.curDeep++;//深度+1this.makeCanditateSet();//创建候选集this.makeFrequentSet();//创建频繁集}//计算最大频繁集this.makeMaxFrequentSet();//计算规则this.makeRules();}/**8*创建规则**/privatevoidmakeRules(){intruleNum=0;for(Objectform:this.maxFrequentSetList){TransactionFormtf=(TransactionForm)form;ruleNum=(1tf.getItems().size())-2;for(inti=1;i=ruleNum;i++){Rulerule=newRule();TransactionFormA=newTransactionForm();TransactionFormB=newTransactionForm();intj=0;Setitems=tf.getItems();for(Objectobject:items){Stringitem=(String)object;if(((1j)&i)!=0){A.addItem(item);}else{B.addItem(item);}j++;}TransactionFormAB=newTransactionForm();AB.addAll(A.getItems());AB.addAll(B.getItems());if(getSupportNum(AB)=(getSupportNum(A)*minConfidence)){doubleconfidence=this.getSupportNum(AB)*1.0/this.getSupportNum(A);rule.setA(A);rule.setB(B);rule.setConfidence(confidence);this.ruleList.add(rule);}}}}/***计算1项候选集**/privatevoidmakeCanditateSet1(){9SetkeySet=container.keySet();IteratorkeyIterator=keySet.iterator();StringTID;TransactionFormtransactionForm;Listlist=newArrayList();//存放1项候选集Setitem1=newTreeSet();while(keyIterator.hasNext()){TID=(String)keyIterator.next();transactionForm=(TransactionForm)(container.get(TID));Setitems=transactionForm.getItems();for(Objectobject:items){item1.add(object);}}elementSet.addAll(item1);for(Objectobject:item1){TransactionFormtf=newTransactionForm();tf.addItem(object);list.add(tf);}this.canditateSetList.add(list);this.curDeep=1;}/***计算k项候选集**/privatevoidmakeCanditateSet(){//读取前一个频繁集ListfrontFrequentSetList=(List)this.frequentSetList.get(this.curDeep-2);ListnewCanditateList=newArrayList();for(Objectobj:frontFrequentSetList){TransactionFormtf=(TransactionForm)obj;for(Objectitem:this.elementSet){Setitems=newTreeSet();items.addAll(tf.getItems());items.add(item);if(items.size()!=this.curDeep){continue;}10TransactionFormnewTransactionForm=newTransactionForm();newTransactionForm.setItems(items);if(this.getSupportNum(newTransactionForm)!=0){if(!isExit(newCanditateList,newTransactionForm)){newCanditateList.add(newTransactionForm);}}}}this.canditateSetList.add(newCanditateList);}/***判断链表中是否存在相同的交易表单**/privatebooleanisExit(Listlist,TransactionFormnewForm){for(Objectform:list){SetcurSet=((TransactionForm)form).getItems();SetnewSet=newForm.getItems();SettempSet=newTreeSet();tempSet.addAll(curSet);intbeginSize=tempSet.size();tempSet.addAll(newSet);intendSize=tempSet.size();if(endSize=beginSize){//只要有一个集合没变大,说明已存在returntrue;}}returnfalse;}/***创建最大频繁集**/privatevoidmakeMaxFrequentSet(){for(inti=frequentSetList.size()-1;i=0;i--){Listlist=(List)frequentSetList.get(i);for(Objectform:list){if(!isExit(maxFrequentSetList,(TransactionForm)form)){11this.maxFrequentSetList.add(form);}}}}/***创建频繁集**/privatevoidmakeFrequentSet(){ListfrequentList=newArrayList();ListcanditateList=(List)this.canditateSetList.get(this.curDeep-1);for(Objectform:canditateList){TransactionFormtf=(TransactionForm)form;if(this.getSupportNum(tf)=minSupport*totalSize){frequentList.add(tf);}}this.frequentSetList.add(frequentList);if(frequentList.size()==0){this.stopAnalyse();//如果没有新的频繁集,则可停止分析}}/***创建频繁1项集**/privatevoidmakeFrequentSet1(){ListcanditateList=(List)canditateSetList.get(0);ListfrequentList=newArrayList();for(Objectobject:canditateList){TransactionFormtf=(TransactionForm)object;if(this.getSupportNum(tf)=minSupport*totalSize){frequentList.add(tf);}}this.frequentSetList.add(frequentList);if(frequentList.size()==0){this.