⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 apriori.java

📁 apriori演算法於JAVA環境下開發 用於資料探勘分類產生規則
💻 JAVA
字号:
/**
 * @(#)Apriori.java
 *
 * This class controls the various aspects of the program such as candidate
 * itemset generation and hashtree population.
 *
 * @author Adrian Bright
 */
import java.util.*;


public class Apriori
{
	private int minSup;
	private int minConf;

	/**
     * Apriori
     * @param itemsFile File containing list of items in format {itemID,itemName}.
	 * @param transactionFile File containing list of transactions in format {transactionID,transactionItem(1),transactionItem(2),...,transactionItem(n).
	 * @param outputFile File to which the list of frequent itemsets is to be written.
	 * @param minSup The minimum support for the search.
     */
	public Apriori(String itemsFile,String transactionsFile,String outputFile,int mSup)
	{
		LinkedList currentItemSets;
		LinkedList frequentOneItemSets;
		LinkedList transactionList;
		LinkedList itemsRef;
		HashTree tree;
		int maxTransactionLength;
		/* minSup as it has to be used for these calculations */
		int practicalMinSup;
		
		setMinSup(mSup);
		ItemsInput itemsInput = new ItemsInput(itemsFile);
		
		itemsRef = itemsInput.getItemsRef();
		itemsInput.printItems();
		frequentOneItemSets = itemsInput.findCandidateOneItems(transactionsFile); // gets 1-itemsets
		practicalMinSup = (minSup*itemsInput.getTransactionNum())/100;
		frequentOneItemSets = itemsInput.removeInfrequentItemsets(frequentOneItemSets,practicalMinSup);
		//itemsInput.printOneItemsets(frequentOneItemSets);
		maxTransactionLength = itemsInput.getMaxTransactionLength();
		tree = new HashTree(itemsRef);
		tree.addCandidates(frequentOneItemSets);
		currentItemSets = frequentOneItemSets;
		for (int count = 1; count < maxTransactionLength; count++)
		{
			currentItemSets = itemsInput.generateNItemsets(frequentOneItemSets,currentItemSets,count); // gets k-itemsets
			tree.addCandidates(currentItemSets);
			tree.passTransactions(count+1,transactionsFile);
			tree.removeInfrequentItemsets(practicalMinSup);
			currentItemSets = tree.getFrequentNItemsets(count+1);
		}
		tree.printAllFrequentItemsets(itemsInput.getTransactionNum(),minSup);
		tree.printAllFrequentItemsets(outputFile,itemsInput.getTransactionNum(),minSup);
	}

	/**
     * setMinSup Sets the minimum support
	 * @param val The minimum support for the search
     */
	public void setMinSup(int val)
	{
		minSup = val;
	}

	/**
     * setMinConf Sets the minimum confidence (not actually used in this implementation)
	 * @param val The minimum confidence for the search
     */
	public void setMinConf(int val)
	{
		minConf = val;
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -