Package weka.associations
Class LabeledItemSet
- java.lang.Object
-
- weka.associations.ItemSet
-
- weka.associations.LabeledItemSet
-
- All Implemented Interfaces:
java.io.Serializable
,RevisionHandler
public class LabeledItemSet extends ItemSet implements java.io.Serializable, RevisionHandler
Class for storing a set of items together with a class label. 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 methods used for item sets in class association rule mining. Because every item set knows its class label the training set can be splitted up virtually.- Version:
- $Revision: 1.5 $
- Author:
- Stefan Mutter (mutter@cs.waikato.ac.nz)
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description LabeledItemSet(int totalTrans, int classLabel)
Constructor
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static FastVector
deleteItemSets(FastVector itemSets, int minSupport, int maxSupport)
Deletes all item sets that don't have minimum support and have more than maximum supportstatic Instances
divide(Instances instances, boolean invert)
Splits the class attribute away.boolean
equalCondset(java.lang.Object itemSet)
Compares two item setsboolean
equals(java.lang.Object itemSet)
Tests if two item sets are equal.FastVector[]
generateRules(double minConfidence, boolean noPrune)
Generates rules out of item setsstatic java.util.Hashtable
getHashtable(FastVector itemSets, int initialSize)
Return a hashtable filled with the given item sets.java.lang.String
getRevision()
Returns the revision string.static FastVector
mergeAllItemSets(FastVector 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 FastVector
pruneItemSets(FastVector toPrune, java.util.Hashtable kMinusOne)
Prunes a set of (k)-item sets using the given (k-1)-item sets.static FastVector
singletons(Instances instancesNoClass, Instances classes)
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.void
upDateCounter(Instance instanceNoClass, Instance instanceClass)
Updates counter of item set with respect to given transaction.static void
upDateCounters(FastVector itemSets, Instances instancesNoClass, Instances instancesClass)
Updates counter of a specific item set-
Methods inherited from class weka.associations.ItemSet
containedBy, counter, hashCode, itemAt, items, pruneRules, setCounter, setItem, setItemAt, singletons, toString, upDateCounter, upDateCounters
-
-
-
-
Method Detail
-
deleteItemSets
public static FastVector deleteItemSets(FastVector itemSets, int minSupport, int maxSupport)
Deletes all item sets that don't have minimum support and have more than maximum 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
public final boolean equals(java.lang.Object itemSet)
Tests if two item sets are equal.
-
equalCondset
public final boolean equalCondset(java.lang.Object itemSet)
Compares two item sets- Parameters:
itemSet
- an item set- Returns:
- true if the the item sets are equal, false otherwise
-
getHashtable
public static java.util.Hashtable getHashtable(FastVector 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 tableinitialSize
- the initial size of the hashtable- Returns:
- the generated hashtable
-
mergeAllItemSets
public static FastVector mergeAllItemSets(FastVector 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
- the total number of transactionsitemSets
- the set of (k-1)-item setssize
- the value of (k-1)- Returns:
- the generated (k)-item sets
-
divide
public static Instances divide(Instances instances, boolean invert) throws java.lang.Exception
Splits the class attribute away. Depending on the invert flag, the instances without class attribute or only the class attribute of all instances is returned- Parameters:
instances
- the instancesinvert
- flag; if true only the class attribute remains, otherweise the class attribute is the only attribute that is deleted.- Returns:
- Instances without the class attribute or instances with only the class attribute
- Throws:
java.lang.Exception
- exception if instances cannot be splitted
-
singletons
public static FastVector singletons(Instances instancesNoClass, Instances classes) throws java.lang.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. Each item set knows its class label.- Parameters:
instancesNoClass
- instances without the class attributeclasses
- the values of the class attribute sorted according to instances- Returns:
- a set of item sets, each containing a single item
- Throws:
java.lang.Exception
- if singletons can't be generated successfully
-
pruneItemSets
public static FastVector pruneItemSets(FastVector toPrune, java.util.Hashtable 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
-
support
public final int support()
Outputs the support for an item set.
-
upDateCounter
public final void upDateCounter(Instance instanceNoClass, Instance instanceClass)
Updates counter of item set with respect to given transaction.- Parameters:
instanceNoClass
- instances without the class attributeinstanceClass
- the values of the class attribute sorted according to instances
-
upDateCounters
public static void upDateCounters(FastVector itemSets, Instances instancesNoClass, Instances instancesClass)
Updates counter of a specific item set- Parameters:
itemSets
- an item setsinstancesNoClass
- instances without the class attributeinstancesClass
- the values of the class attribute sorted according to instances
-
generateRules
public final FastVector[] generateRules(double minConfidence, boolean noPrune)
Generates rules out of item sets- Parameters:
minConfidence
- the minimum confidencenoPrune
- flag indicating whether the rules are pruned accoridng to the minimum confidence value- Returns:
- a set of rules
-
getRevision
public java.lang.String getRevision()
Returns the revision string.- Specified by:
getRevision
in interfaceRevisionHandler
- Overrides:
getRevision
in classItemSet
- Returns:
- the revision
-
-