Package weka.associations

# Class ItemSet

java.lang.Object
weka.associations.ItemSet

All Implemented Interfaces:
  `Serializable`, `RevisionHandler`

Direct Known Subclasses:
  `AprioriItemSet`, `LabeledItemSet`

public class ItemSet extends Object implements Serializable, RevisionHandler
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.

Version:
  $Revision: 13477 $
Author:
  Eibe Frank (eibe@cs.waikato.ac.nz)
See Also:
  - Serialized Form

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `ItemSet(int totalTrans)`
  Constructor
  `ItemSet(int[] array)`
  Contsructor
  `ItemSet(int totalTrans, int[] array)`
  Constructor

- ## Method Summary

  Modifier and Type
  Method
  Description
  `boolean`
  `containedBy(Instance instance)`
  Checks if an instance contains an item set.
  `boolean`
  `containedByTreatZeroAsMissing(Instance instance)`
  Checks if an instance contains an item set.
  `int`
  `counter()`
  Gets the counter
  `static ArrayList<Object>`
  `deleteItemSets(ArrayList<Object> itemSets, int minSupport, int maxSupport)`
  Deletes all item sets that don't have minimum support.
  `boolean`
  `equals(Object itemSet)`
  Tests if two item sets are equal.
  `static Hashtable<ItemSet,Integer>`
  `getHashtable(ArrayList<Object> itemSets, int initialSize)`
  Return a hashtable filled with the given item sets.
  `int[]`
  `getItems()`
  Get the item array
  `String`
  `getRevision()`
  Returns the revision string.
  `int`
  `getTotalTransactions()`
  Get the total number of transactions
  `int`
  `hashCode()`
  Produces a hash code for a item set.
  `int`
  `itemAt(int k)`
  Gest the index of the value of the specified attribute
  `int[]`
  `items()`
  Gest the item set as an int array
  `static ArrayList<Object>`
  `mergeAllItemSets(ArrayList<Object> itemSets, int size, int totalTrans)`
  Merges all item sets in the set of (k-1)-item sets to create the (k)-item sets and updates the counters.
  `static ArrayList<Object>`
  `pruneItemSets(ArrayList<Object> toPrune, Hashtable<ItemSet,Integer> kMinusOne)`
  Prunes a set of (k)-item sets using the given (k-1)-item sets.
  `static void`
  `pruneRules(ArrayList<Object>[] rules, double minConfidence)`
  Prunes a set of rules.
  `void`
  `setCounter(int count)`
  Sets the counter
  `void`
  `setItem(int[] items)`
  Sets an item sets
  `void`
  `setItemAt(int value, int k)`
  Sets the index of an attribute value
  `static ArrayList<Object>`
  `singletons(Instances instances)`
  Converts the header info of the given set of instances into a set of item sets (singletons).
  `int`
  `support()`
  Outputs the support for an item set.
  `String`
  `toString(Instances instances)`
  Returns the contents of an item set as a string.
  `String`
  `toString(Instances instances, char outerDelim, char innerDelim)`
  Returns the contents of an item set as a delimited string.
  `void`
  `upDateCounter(Instance instance)`
  Updates counter of item set with respect to given transaction.
  `static void`
  `upDateCounters(ArrayList<Object> itemSets, Instances instances)`
  Updates counters for a set of item sets and a set of instances.
  `static void`
  `upDateCountersTreatZeroAsMissing(ArrayList<Object> itemSets, Instances instances)`
  Updates counters for a set of item sets and a set of instances.
  `void`
  `updateCounterTreatZeroAsMissing(Instance instance)`
  Updates counter of item set with respect to given transaction.

  ### Methods inherited from class java.lang.Object

  `getClass, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### ItemSet

    public ItemSet(int totalTrans)
    Constructor
    Parameters:
      `totalTrans` - the total number of transactions in the data

  - ### ItemSet

    public ItemSet(int totalTrans, int[] array)
    Constructor
    Parameters:
      `totalTrans` - the total number of transactions in the data
      `array` - the attribute values encoded in an int array

  - ### ItemSet

    public ItemSet(int[] array)
    Contsructor
    Parameters:
      `array` - the item set represented as an int array

- ## Method Details

  - ### containedByTreatZeroAsMissing

    public boolean containedByTreatZeroAsMissing(Instance instance)
    Checks if an instance contains an item set.
    Parameters:
      `instance` - the instance to be tested
    Returns:
      true if the given instance contains this item set

  - ### containedBy

    public boolean containedBy(Instance instance)
    Checks if an instance contains an item set.
    Parameters:
      `instance` - the instance to be tested
    Returns:
      true if the given instance contains this item set

  - ### deleteItemSets

    public static ArrayList<Object> deleteItemSets(ArrayList<Object> itemSets, int minSupport, int maxSupport)
    Deletes all item sets that don't have minimum support.
    Parameters:
      `maxSupport` - the maximum support
      `itemSets` - the set of item sets to be pruned
      `minSupport` - the minimum number of transactions to be covered
    Returns:
      the reduced set of item sets

  - ### equals

    public boolean equals(Object itemSet)
    Tests if two item sets are equal.
    Overrides:
      `equals` in class `Object`
    Parameters:
      `itemSet` - another item set
    Returns:
      true if this item set contains the same items as the given one

  - ### getHashtable

    public static Hashtable<ItemSet,Integer> getHashtable(ArrayList<Object> itemSets, int initialSize)
    Return a hashtable filled with the given item sets.
    Parameters:
      `itemSets` - the set of item sets to be used for filling the hash table
      `initialSize` - the initial size of the hashtable
    Returns:
      the generated hashtable

  - ### hashCode

    public int hashCode()
    Produces a hash code for a item set.
    Overrides:
      `hashCode` in class `Object`
    Returns:
      a hash code for a set of items

  - ### mergeAllItemSets

    public static ArrayList<Object> mergeAllItemSets(ArrayList<Object> itemSets, int size, int totalTrans)
    Merges all item sets in the set of (k-1)-item sets to create the (k)-item sets and updates the counters.
    Parameters:
      `totalTrans` - thetotal number of transactions
      `itemSets` - the set of (k-1)-item sets
      `size` - the value of (k-1)
    Returns:
      the generated (k)-item sets

  - ### pruneItemSets

    public static ArrayList<Object> pruneItemSets(ArrayList<Object> toPrune, Hashtable<ItemSet,Integer> kMinusOne)
    Prunes a set of (k)-item sets using the given (k-1)-item sets.
    Parameters:
      `toPrune` - the set of (k)-item sets to be pruned
      `kMinusOne` - the (k-1)-item sets to be used for pruning
    Returns:
      the pruned set of item sets

  - ### pruneRules

    public static void pruneRules(ArrayList<Object>[] rules, double minConfidence)
    Prunes a set of rules.
    Parameters:
      `rules` - a two-dimensional array of lists of item sets. The first list of item sets contains the premises, the second one the consequences.
      `minConfidence` - the minimum confidence the rules have to have

  - ### singletons

    public static ArrayList<Object> singletons(Instances instances) throws Exception
    Converts the header info of the given set of instances into a set of item sets (singletons). The ordering of values in the header file determines the lexicographic order.
    Parameters:
      `instances` - the set of instances whose header info is to be used
    Returns:
      a set of item sets, each containing a single item
    Throws:
      `Exception` - if singletons can't be generated successfully

  - ### support

    public int support()
    Outputs the support for an item set.
    Returns:
      the support

  - ### toString

    public String toString(Instances instances)
    Returns the contents of an item set as a string.
    Parameters:
      `instances` - contains the relevant header information
    Returns:
      string describing the item set

  - ### toString

    public String toString(Instances instances, char outerDelim, char innerDelim)
    Returns the contents of an item set as a delimited string.
    Parameters:
      `instances` - contains the relevant header information
      `outerDelim` - the outer delimiter
      `innerDelim` - the inner delimiter
    Returns:
      string describing the item set

  - ### upDateCounter

    public void upDateCounter(Instance instance)
    Updates counter of item set with respect to given transaction.
    Parameters:
      `instance` - the instance to be used for ubdating the counter

  - ### updateCounterTreatZeroAsMissing

    public void updateCounterTreatZeroAsMissing(Instance instance)
    Updates counter of item set with respect to given transaction.
    Parameters:
      `instance` - the instance to be used for ubdating the counter

  - ### upDateCounters

    public static void upDateCounters(ArrayList<Object> itemSets, Instances instances)
    Updates counters for a set of item sets and a set of instances.
    Parameters:
      `itemSets` - the set of item sets which are to be updated
      `instances` - the instances to be used for updating the counters

  - ### upDateCountersTreatZeroAsMissing

    public static void upDateCountersTreatZeroAsMissing(ArrayList<Object> itemSets, Instances instances)
    Updates counters for a set of item sets and a set of instances.
    Parameters:
      `itemSets` - the set of item sets which are to be updated
      `instances` - the instances to be used for updating the counters

  - ### counter

    public int counter()
    Gets the counter
    Returns:
      the counter

  - ### items

    public int[] items()
    Gest the item set as an int array
    Returns:
      int array represneting an item set

  - ### itemAt

    public int itemAt(int k)
    Gest the index of the value of the specified attribute
    Parameters:
      `k` - the attribute index
    Returns:
      the index of the attribute value

  - ### setCounter

    public void setCounter(int count)
    Sets the counter
    Parameters:
      `count` - the counter

  - ### setItem

    public void setItem(int[] items)
    Sets an item sets
    Parameters:
      `items` - an int array representing an item set

  - ### setItemAt

    public void setItemAt(int value, int k)
    Sets the index of an attribute value
    Parameters:
      `value` - the inex of the attribute value
      `k` - the index of the attribute

  - ### getItems

    public int[] getItems()
    Get the item array
    Returns:
      the item array

  - ### getTotalTransactions

    public int getTotalTransactions()
    Get the total number of transactions
    Returns:
      the total number of transactions

  - ### getRevision

    public String getRevision()
    Returns the revision string.
    Specified by:
      `getRevision` in interface `RevisionHandler`
    Returns:
      the revision