Package weka.associations
Class ItemSet
java.lang.Object
weka.associations.ItemSet
- All Implemented Interfaces:
Serializable
,RevisionHandler
- Direct Known Subclasses:
AprioriItemSet
,LabeledItemSet
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: 13476 $
- Author:
- Eibe Frank (eibe@cs.waikato.ac.nz)
- See Also:
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionboolean
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 counterdeleteItemSets
(ArrayList<Object> itemSets, int minSupport, int maxSupport) Deletes all item sets that don't have minimum support.boolean
Tests if two item sets are equal.getHashtable
(ArrayList<Object> itemSets, int initialSize) Return a hashtable filled with the given item sets.int[]
getItems()
Get the item arrayReturns the revision string.int
Get the total number of transactionsint
hashCode()
Produces a hash code for a item set.int
itemAt
(int k) Gest the index of the value of the specified attributeint[]
items()
Gest the item set as an int arraymergeAllItemSets
(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.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 countervoid
setItem
(int[] items) Sets an item setsvoid
setItemAt
(int value, int k) Sets the index of an attribute valuesingletons
(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.Returns the contents of an item set as a string.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.
-
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 dataarray
- 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
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
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 supportitemSets
- the set of item sets to be prunedminSupport
- the minimum number of transactions to be covered- Returns:
- the reduced set of item sets
-
equals
Tests if two item sets are equal. -
getHashtable
Return a hashtable filled with the given item sets.- Parameters:
itemSets
- the set of item sets to be used for filling the hash tableinitialSize
- the initial size of the hashtable- Returns:
- the generated hashtable
-
hashCode
public int hashCode()Produces a hash code for a item set. -
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 transactionsitemSets
- the set of (k-1)-item setssize
- 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 prunedkMinusOne
- the (k-1)-item sets to be used for pruning- Returns:
- the pruned set of item sets
-
pruneRules
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
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
Returns the contents of an item set as a string.- Parameters:
instances
- contains the relevant header information- Returns:
- string describing the item set
-
toString
Returns the contents of an item set as a delimited string.- Parameters:
instances
- contains the relevant header informationouterDelim
- the outer delimiterinnerDelim
- the inner delimiter- Returns:
- string describing the item set
-
upDateCounter
Updates counter of item set with respect to given transaction.- Parameters:
instance
- the instance to be used for ubdating the counter
-
updateCounterTreatZeroAsMissing
Updates counter of item set with respect to given transaction.- Parameters:
instance
- the instance to be used for ubdating the counter
-
upDateCounters
Updates counters for a set of item sets and a set of instances.- Parameters:
itemSets
- the set of item sets which are to be updatedinstances
- 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 updatedinstances
- 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 valuek
- 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
Returns the revision string.- Specified by:
getRevision
in interfaceRevisionHandler
- Returns:
- the revision
-