copy Bookmark http://space.itpub.net/12443821
上一篇 / 下一篇 2008-05-11 17:03:45 / 个人分类:数据挖掘
毕业设计五:用JAVA实现Apriori算法
一、开发环境:
操作系统:Windwos xp sp2
开发平台:Eclipse6.0.1
开发语言:JAVA
算法的输入:事务数据库,最小支持度
算法输出:频繁项集的集合,关联规则的集合
二、产生频繁项集:
(1)、首先由数据库读取出所有的事务数据;
(2)、找出频繁一项集的集合L1,它由满足最小支持度的候选一项集组成,将其加入到频繁项集的集合中;
(3)、L1与L1连接,产生候选2项集的集合C2。然后剪枝,即如果候选2项集的某个子集不在一项频繁集中(即不是频繁的),那么删除该候选。
(4)、扫描事务数据,计算C2中每个候选项集的支持度计数。
(5)、确定频繁2项集的集合L2,它由满足最小支持度的C2中的候选2项集组成。将其加入到频繁项集的集合中;
(6)、当Lk-1不空(k>=2),重复执行(3)~(5)。
(7)、输到频繁项集的集合到文件中;
(1)、对每个频繁项集l,产生l的所有非空子集;
(2)、对l的每个非空子集s,产生规则“s=>(l-s)”;
(3)、如果该规则不存在,则加入到规则集中;
(4)、输出置信度大于最小置信度阈值的规则。
publicstaticvoidmain(String[] args)throwsIOException {
//TODOAuto-generated method stub
TransactionSet transactionSet =newTransactionSet();
Apriori apriori =newApriori(transactionSet,0.01);
//测试APRIORI算法,产生所有的频繁项集
List<List<ItemSet>> allFrequentItemSets = apriori.runApriori();
apriori.dumpAllFrequentItemSetsToFile(allFrequentItemSets);
//测试产生关联规则
List<AssociationRule> associationRuleList =newArrayList<AssociationRule> ();
associationRuleList = apriori.generateAssociationRules(allFrequentItemSets);
apriori.dumpAssociationRulesToFile(associationRuleList,0.5);
}
五、产生的频繁项集:
略
六、产生的关联规则:
{ {XCB,GJC,XGB} } => { {COLLEGE} } Confidence: 0.9777777777777779
{ {XCB,GJC,COLLEGE} } => { {XGB} } Confidence: 0.5365853658536586
{ {XCB,XGB,COLLEGE} } => { {GJC} } Confidence: 0.6875
{ {GJC,XGB,COLLEGE} } => { {XCB} } Confidence: 0.7586206896551725
{ {XCB,RSC} } => { {GJC,COLLEGE} } Confidence: 0.5492957746478874
{ {GJC,RSC} } => { {XCB,COLLEGE} } Confidence: 0.629032258064516
{ {XCB,GJC,RSC} } => { {COLLEGE} } Confidence: 0.975
{ {XCB,COLLEGE,RSC} } => { {GJC} } Confidence: 0.6000000000000001
{ {GJC,COLLEGE,RSC} } => { {XCB} } Confidence: 0.6724137931034483
七、验证实验结果:
SQL> select url from weblog where cip='219.142.53.28' order by access_time;
xgb
college
kjc
xyw
jwc
xcb
rcxq
SQL> select url from weblog where cip='219.159.103.3' order by access_time;
index
SQL> select url from weblog where cip='220.173.139.228' order by access_time;
已选择74行。
SQL> select url from weblog where cip='162.105.146.11' order by access_time;
已选择185行。
sphy
gjc
rsc
xyzx
xbjy
选取了访问页面数较多的四个用户进行观察。
第一个用户符合如下规则:
{ {XCB,XGB} } => { {COLLEGE} } Confidence: 0.9275362318840579
第二和第三个用户:
{ {JWC} } => { {INDEX_PAGE} } Confidence: 0.9229898074745188
第四个用户:
{ {GJC,RSC} } => { {COLLEGE} } Confidence: 0.9354838709677418
发现实验的结果,与用户的访问行为大致相符。
oracle_8i
导入论坛 引用链接 收藏 分享给好友 推荐到圈子 管理 举报
TAG:
评分:0
显示全部
内容
昵称
验证
提交评论
xyzlotus