📄 apriori.java
字号:
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/**
* Title: prudsys basket analysis
* Description: Basket analysis algorithms
* Copyright: Copyright (c) 2001
* Company: PRUDENTIAL SYSTEMS SOFTWARE GmbH
* @author Stefan Ludwig
* @author Michael Thess
* @version 1.0
*/
package com.prudsys.pdm.Models.Sequential.Algorithms.SeqSimple;
/**
* Apriori - Data Mining Algorithm. Old implementation of 1999
* by Stefan Ludwig. New implementation in AprioriOptimized
* by Alexej Grinyuk is magnitudes faster.
*
* @author Stefan Ludwig
* @author Michael Thess
* @version 1.3, 2002/08/12
*/
public class Apriori {
static boolean dbg = false;
/**
* Implements the part of finding large itemsets of
* Algorithm Apriori (by Rakesh Agrawal).
*
* @param transSet transaction set
* @param minsupp minimal support
* @return result as list of large itemsets
*/
protected static ItemSetList AprioriAlgLITS(TransactionSet transSet,
double minsupp) {
return AprioriAlgLITS(transSet, 0, minsupp, 1, -1);
}
/**
* Implements the part of finding large itemsets of
* Algorithm Apriori (by Rakesh Agrawal).
*
* @param transSet transaction set
* @param minsuppcount minimum support count, ignore if <=0
* @param minsupp minimal support
* @param minItemSize minimum size of rules
* @param maxItemSize maximum size of rules, -1 for unbounded
* @return result as list of large itemsets
*/
protected static ItemSetList AprioriAlgLITS(TransactionSet transSet,
int minsuppcount, double minsupp,
int minItemSize, int maxItemSize) {
// Create list of large itemsets:
ItemSetList largeItemSetList = new ItemSetList();
// Determine minimal support:
if (minsuppcount <= 0)
transSet.setMinSuppCount(minsupp);
else
transSet.setMinSuppCount(minsuppcount);
int minSuppCount = transSet.getMinSuppCount();
if (dbg) System.out.println("minSuppCount = " + minSuppCount);
// Find large 1-itemsets:
int itemSetSize = 1;
ItemSetList itemSetList = new ItemSetList(); //contains "ItemSet"s
largeItemSetList = transSet.buildHashTable();
if (dbg) System.out.println("Large 1-Itemsets w/ minSuppCount:");
if (dbg) largeItemSetList.print();
// Convert the large 1-itemsets to a tree
ItemTree itree = new ItemTree(largeItemSetList);
itree.setTransactionSet(transSet);
// Find remaining large itemsets:
int depth = 1000;
if (maxItemSize > -1)
depth = maxItemSize;
for (int i = 1; i < depth; i++) {
if (! itree.filltree(i) )
break;
};
if (dbg) itree.printtree(itree.tree);
// Copy large itemsets:
largeItemSetList = itree.getLargeItemSetList(itree.tree);
if (dbg) System.out.println("L A R G E Itemset list:");
if (dbg) largeItemSetList.print();
return largeItemSetList;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -