• 大小: 5KB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2021-05-20
  • 语言: Java
  • 标签: Aprior  Java  

资源简介

Java语言实现的Apriori算法,数据可由excel数据表格提供,eclipse导入即可运行

资源截图

代码片段和文件信息

package asocciationRule.apriori;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;

public class AprioriAlgorithm {
private Map> txDatabase; // 事务数据库
private Float minSup; // 最小支持度
private Float minConf; // 最小置信度
private Integer txDatabaseCount; // 事务数据库中的事务数

private Map>> freqItemSet; // 频繁项集集合
private Map Set>> assiciationRules; // 频繁关联规则集合

public AprioriAlgorithm(Map> txDatabase Float minSup
Float minConf) {
this.txDatabase = txDatabase;
this.minSup = minSup;
this.minConf = minConf;
this.txDatabaseCount = this.txDatabase.size();
freqItemSet = new TreeMap>>();
assiciationRules = new HashMap Set>>();
}

public Map Float> getFreq1ItemSet() {//zzx 生成一阶频繁项集
Map Float> freq1ItemSetMap = new HashMap Float>();
Map Integer> candFreq1ItemSet = this.getCandFreq1ItemSet();
Iterator Integer>> it = candFreq1ItemSet
.entrySet().iterator();
while (it.hasNext()) {
Map.Entry Integer> entry = it.next();
// 计算支持度
Float supported = new Float(entry.getValue().toString())
/ new Float(txDatabaseCount);
if (supported >= minSup) {
freq1ItemSetMap.put(entry.getKey() supported);
}
}
return freq1ItemSetMap;
}

public Map Integer> getCandFreq1ItemSet() {
Map Integer> candFreq1ItemSetMap = new HashMap Integer>();
Iterator>> it = txDatabase.entrySet()
.iterator();
// 统计支持数,生成候选频繁1-项集
while (it.hasNext()) {
Map.Entry> entry = it.next();
Set itemSet = entry.getValue();
for (String item : itemSet) {
Set key = new HashSet();
key.add(item.trim());
if (!candFreq1ItemSetMap.containsKey(key)) {
Integer value = 1;
candFreq1ItemSetMap.put(key value);
} else {
Integer value = 1 + candFreq1ItemSetMap.get(key);
candFreq1ItemSetMap.put(key value);
}
}
}
return candFreq1ItemSetMap;
}

/*
 * zzx生成m+1阶候选项集
 */
public Set> aprioriGen(int m Set> freqMItemSet) {
Set> candFreqKItemSet = new HashSet>();
Iterator> it = freqMItemSet.iterator();
Set originalItemSet = null;
while (it.hasNext()) {
originalItemSet = it.next();
Iterator> itr = this.getIterator(originalItemSetfreqMItemSet);
while (itr.hasNext()) {
Set identicalSet = new HashSet(); // 两个项集相同元素的集合(集合的交运算)
identicalSet.addAll(originalItemSet);
Set set = itr.next();
identicalSet.retainAll(set); // identicalSet中剩下的元素是identicalSet与set集合中相同的元素

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     文件        9780  2016-03-23 20:58  apriori\AprioriAlgorithm.java
     文件        2248  2014-09-15 15:15  apriori\ProperSubsetCombination.java
     文件        2242  2014-09-15 15:15  apriori\TestAprioriAlgorithm.java
     目录           0  2018-10-27 21:30  apriori\

评论

共有 条评论