Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
The Waikato Environment for Knowledge Analysis (WEKA), a machine
learning workbench. This is the stable version. Apart from bugfixes, this version
does not receive any other updates.
/*
* 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 3 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, see .
*/
/*
* ItemSet.java
* Copyright (C) 1999-2012 University of Waikato, Hamilton, New Zealand
*
*/
package weka.associations;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.Hashtable;
import weka.core.Instance;
import weka.core.Instances;
import weka.core.RevisionHandler;
import weka.core.RevisionUtils;
import weka.core.WekaEnumeration;
/**
* Class for storing a set of items. Item sets are stored in a lexicographic
* order, which is determined by the header information of the set of instances
* used for generating the set of items. All methods in this class assume that
* item sets are stored in lexicographic order. The class provides the general
* methods used for item sets in class - and standard association rule mining.
*
* @author Eibe Frank ([email protected])
* @version $Revision: 12014 $
*/
public class ItemSet implements Serializable, RevisionHandler {
/** for serialization */
private static final long serialVersionUID = 2724000045282835791L;
/** The items stored as an array of of ints. */
protected int[] m_items;
/** Counter for how many transactions contain this item set. */
protected int m_counter;
/**
* Holds support of consequence only in the case where this ItemSet is
* a consequence of a rule (as m_counter in this case actually holds the
* support of the rule as a whole, i.e. premise and consequence)
*/
protected int m_secondaryCounter;
/** The total number of transactions */
protected int m_totalTransactions;
/**
* Constructor
*
* @param totalTrans the total number of transactions in the data
*/
public ItemSet(int totalTrans) {
m_totalTransactions = totalTrans;
}
/**
* Constructor
*
* @param totalTrans the total number of transactions in the data
* @param array the attribute values encoded in an int array
*/
public ItemSet(int totalTrans, int[] array) {
m_totalTransactions = totalTrans;
m_items = array;
m_counter = 1;
}
/**
* Contsructor
*
* @param array the item set represented as an int array
*/
public ItemSet(int[] array) {
m_items = array;
m_counter = 0;
}
/**
* Checks if an instance contains an item set.
*
* @param instance the instance to be tested
* @return true if the given instance contains this item set
*/
public boolean containedByTreatZeroAsMissing(Instance instance) {
if (instance instanceof weka.core.SparseInstance) {
int numInstVals = instance.numValues();
int numItemSetVals = m_items.length;
for (int p1 = 0, p2 = 0; p1 < numInstVals || p2 < numItemSetVals;) {
int instIndex = Integer.MAX_VALUE;
if (p1 < numInstVals) {
instIndex = instance.index(p1);
}
int itemIndex = p2;
if (m_items[itemIndex] > -1) {
if (itemIndex != instIndex) {
return false;
} else {
if (instance.isMissingSparse(p1)) {
return false;
}
if (m_items[itemIndex] != (int) instance.valueSparse(p1)) {
return false;
}
}
p1++;
p2++;
} else {
if (itemIndex < instIndex) {
p2++;
} else if (itemIndex == instIndex) {
p2++;
p1++;
}
}
}
} else {
for (int i = 0; i < instance.numAttributes(); i++) {
if (m_items[i] > -1) {
if (instance.isMissing(i) || (int) instance.value(i) == 0) {
return false;
}
if (m_items[i] != (int) instance.value(i)) {
return false;
}
}
}
}
return true;
}
/**
* Checks if an instance contains an item set.
*
* @param instance the instance to be tested
* @return true if the given instance contains this item set
*/
public boolean containedBy(Instance instance) {
for (int i = 0; i < instance.numAttributes(); i++) {
if (m_items[i] > -1) {
if (instance.isMissing(i)) {
return false;
}
if (m_items[i] != (int) instance.value(i)) {
return false;
}
}
}
return true;
}
/**
* Deletes all item sets that don't have minimum support.
*
* @return the reduced set of item sets
* @param maxSupport the maximum support
* @param itemSets the set of item sets to be pruned
* @param minSupport the minimum number of transactions to be covered
*/
public static ArrayList