Package weka.associations
Class Apriori
- java.lang.Object
-
- weka.associations.AbstractAssociator
-
- weka.associations.Apriori
-
- All Implemented Interfaces:
java.io.Serializable
,java.lang.Cloneable
,Associator
,CARuleMiner
,CapabilitiesHandler
,OptionHandler
,RevisionHandler
,TechnicalInformationHandler
public class Apriori extends AbstractAssociator implements OptionHandler, CARuleMiner, TechnicalInformationHandler
Class implementing an Apriori-type algorithm. Iteratively reduces the minimum support until it finds the required number of rules with the given minimum confidence.
The algorithm has an option to mine class association rules. It is adapted as explained in the second reference.
For more information see:
R. Agrawal, R. Srikant: Fast Algorithms for Mining Association Rules in Large Databases. In: 20th International Conference on Very Large Data Bases, 478-499, 1994.
Bing Liu, Wynne Hsu, Yiming Ma: Integrating Classification and Association Rule Mining. In: Fourth International Conference on Knowledge Discovery and Data Mining, 80-86, 1998. BibTeX:@inproceedings{Agrawal1994, author = {R. Agrawal and R. Srikant}, booktitle = {20th International Conference on Very Large Data Bases}, pages = {478-499}, publisher = {Morgan Kaufmann, Los Altos, CA}, title = {Fast Algorithms for Mining Association Rules in Large Databases}, year = {1994} } @inproceedings{Liu1998, author = {Bing Liu and Wynne Hsu and Yiming Ma}, booktitle = {Fourth International Conference on Knowledge Discovery and Data Mining}, pages = {80-86}, publisher = {AAAI Press}, title = {Integrating Classification and Association Rule Mining}, year = {1998} }
Valid options are:-N <required number of rules output> The required number of rules. (default = 10)
-T <0=confidence | 1=lift | 2=leverage | 3=Conviction> The metric type by which to rank rules. (default = confidence)
-C <minimum metric score of a rule> The minimum confidence of a rule. (default = 0.9)
-D <delta for minimum support> The delta by which the minimum support is decreased in each iteration. (default = 0.05)
-U <upper bound for minimum support> Upper bound for minimum support. (default = 1.0)
-M <lower bound for minimum support> The lower bound for the minimum support. (default = 0.1)
-S <significance level> If used, rules are tested for significance at the given level. Slower. (default = no significance testing)
-I If set the itemsets found are also output. (default = no)
-R Remove columns that contain all missing values (default = no)
-V Report progress iteratively. (default = no)
-A If set class association rules are mined. (default = no)
-c <the class index> The class index. (default = last)
- Version:
- $Revision: 9096 $
- Author:
- Eibe Frank (eibe@cs.waikato.ac.nz), Mark Hall (mhall@cs.waikato.ac.nz), Stefan Mutter (mutter@cs.waikato.ac.nz)
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static Tag[]
TAGS_SELECTION
Metric types.
-
Constructor Summary
Constructors Constructor Description Apriori()
Constructor that allows to sets default values for the minimum confidence and the maximum number of rules the minimum confidence.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
buildAssociations(Instances instances)
Method that generates all large itemsets with a minimum support, and from these all association rules with a minimum confidence.java.lang.String
carTipText()
Returns the tip text for this propertyjava.lang.String
classIndexTipText()
Returns the tip text for this propertyjava.lang.String
deltaTipText()
Returns the tip text for this propertyFastVector[]
getAllTheRules()
returns all the rulesCapabilities
getCapabilities()
Returns default capabilities of the classifier.boolean
getCar()
Gets whether class association ruels are minedint
getClassIndex()
Gets the class indexdouble
getDelta()
Get the value of delta.Instances
getInstancesNoClass()
Gets the instances without the class atrribute.Instances
getInstancesOnlyClass()
Gets only the class attribute of the instances.double
getLowerBoundMinSupport()
Get the value of lowerBoundMinSupport.SelectedTag
getMetricType()
Get the metric typedouble
getMinMetric()
Get the value of minConfidence.int
getNumRules()
Get the value of numRules.java.lang.String[]
getOptions()
Gets the current settings of the Apriori object.boolean
getOutputItemSets()
Gets whether itemsets are output as wellboolean
getRemoveAllMissingCols()
Returns whether columns containing all missing values are to be removedjava.lang.String
getRevision()
Returns the revision string.double
getSignificanceLevel()
Get the value of significanceLevel.TechnicalInformation
getTechnicalInformation()
Returns an instance of a TechnicalInformation object, containing detailed information about the technical background of this class, e.g., paper reference or book this class is based on.double
getUpperBoundMinSupport()
Get the value of upperBoundMinSupport.boolean
getVerbose()
Gets whether algorithm is run in verbose modejava.lang.String
globalInfo()
Returns a string describing this associatorjava.util.Enumeration
listOptions()
Returns an enumeration describing the available options.java.lang.String
lowerBoundMinSupportTipText()
Returns the tip text for this propertystatic void
main(java.lang.String[] args)
Main method.java.lang.String
metricString()
Returns the metric string for the chosen metric typejava.lang.String
metricTypeTipText()
Returns the tip text for this propertyFastVector[]
mineCARs(Instances data)
Method that mines all class association rules with minimum support and with a minimum confidence.java.lang.String
minMetricTipText()
Returns the tip text for this propertyjava.lang.String
numRulesTipText()
Returns the tip text for this propertyjava.lang.String
outputItemSetsTipText()
Returns the tip text for this propertyjava.lang.String
removeAllMissingColsTipText()
Returns the tip text for this propertyvoid
resetOptions()
Resets the options to the default values.void
setCar(boolean flag)
Sets class association rule miningvoid
setClassIndex(int index)
Sets the class indexvoid
setDelta(double v)
Set the value of delta.void
setLowerBoundMinSupport(double v)
Set the value of lowerBoundMinSupport.void
setMetricType(SelectedTag d)
Set the metric type for ranking rulesvoid
setMinMetric(double v)
Set the value of minConfidence.void
setNumRules(int v)
Set the value of numRules.void
setOptions(java.lang.String[] options)
Parses a given list of options.void
setOutputItemSets(boolean flag)
Sets whether itemsets are output as wellvoid
setRemoveAllMissingCols(boolean r)
Remove columns containing all missing values.void
setSignificanceLevel(double v)
Set the value of significanceLevel.void
setUpperBoundMinSupport(double v)
Set the value of upperBoundMinSupport.void
setVerbose(boolean flag)
Sets verbose modejava.lang.String
significanceLevelTipText()
Returns the tip text for this propertyjava.lang.String
toString()
Outputs the size of all the generated sets of itemsets and the rules.java.lang.String
upperBoundMinSupportTipText()
Returns the tip text for this propertyjava.lang.String
verboseTipText()
Returns the tip text for this property-
Methods inherited from class weka.associations.AbstractAssociator
forName, makeCopies, makeCopy
-
-
-
-
Field Detail
-
TAGS_SELECTION
public static final Tag[] TAGS_SELECTION
Metric types.
-
-
Method Detail
-
globalInfo
public java.lang.String globalInfo()
Returns a string describing this associator- Returns:
- a description of the evaluator suitable for displaying in the explorer/experimenter gui
-
getTechnicalInformation
public TechnicalInformation getTechnicalInformation()
Returns an instance of a TechnicalInformation object, containing detailed information about the technical background of this class, e.g., paper reference or book this class is based on.- Specified by:
getTechnicalInformation
in interfaceTechnicalInformationHandler
- Returns:
- the technical information about this class
-
resetOptions
public void resetOptions()
Resets the options to the default values.
-
getCapabilities
public Capabilities getCapabilities()
Returns default capabilities of the classifier.- Specified by:
getCapabilities
in interfaceAssociator
- Specified by:
getCapabilities
in interfaceCapabilitiesHandler
- Overrides:
getCapabilities
in classAbstractAssociator
- Returns:
- the capabilities of this classifier
- See Also:
Capabilities
-
buildAssociations
public void buildAssociations(Instances instances) throws java.lang.Exception
Method that generates all large itemsets with a minimum support, and from these all association rules with a minimum confidence.- Specified by:
buildAssociations
in interfaceAssociator
- Parameters:
instances
- the instances to be used for generating the associations- Throws:
java.lang.Exception
- if rules can't be built successfully
-
mineCARs
public FastVector[] mineCARs(Instances data) throws java.lang.Exception
Method that mines all class association rules with minimum support and with a minimum confidence.- Specified by:
mineCARs
in interfaceCARuleMiner
- Parameters:
data
- the instances for which class association rules should be mined- Returns:
- an sorted array of FastVector (confidence depended) containing the rules and metric information
- Throws:
java.lang.Exception
- if rules can't be built successfully
-
getInstancesNoClass
public Instances getInstancesNoClass()
Gets the instances without the class atrribute.- Specified by:
getInstancesNoClass
in interfaceCARuleMiner
- Returns:
- the instances without the class attribute.
-
getInstancesOnlyClass
public Instances getInstancesOnlyClass()
Gets only the class attribute of the instances.- Specified by:
getInstancesOnlyClass
in interfaceCARuleMiner
- Returns:
- the class attribute of all instances.
-
listOptions
public java.util.Enumeration listOptions()
Returns an enumeration describing the available options.- Specified by:
listOptions
in interfaceOptionHandler
- Returns:
- an enumeration of all the available options.
-
setOptions
public void setOptions(java.lang.String[] options) throws java.lang.Exception
Parses a given list of options. Valid options are:-N <required number of rules output> The required number of rules. (default = 10)
-T <0=confidence | 1=lift | 2=leverage | 3=Conviction> The metric type by which to rank rules. (default = confidence)
-C <minimum metric score of a rule> The minimum confidence of a rule. (default = 0.9)
-D <delta for minimum support> The delta by which the minimum support is decreased in each iteration. (default = 0.05)
-U <upper bound for minimum support> Upper bound for minimum support. (default = 1.0)
-M <lower bound for minimum support> The lower bound for the minimum support. (default = 0.1)
-S <significance level> If used, rules are tested for significance at the given level. Slower. (default = no significance testing)
-I If set the itemsets found are also output. (default = no)
-R Remove columns that contain all missing values (default = no)
-V Report progress iteratively. (default = no)
-A If set class association rules are mined. (default = no)
-c <the class index> The class index. (default = last)
- Specified by:
setOptions
in interfaceOptionHandler
- Parameters:
options
- the list of options as an array of strings- Throws:
java.lang.Exception
- if an option is not supported
-
getOptions
public java.lang.String[] getOptions()
Gets the current settings of the Apriori object.- Specified by:
getOptions
in interfaceOptionHandler
- Returns:
- an array of strings suitable for passing to setOptions
-
toString
public java.lang.String toString()
Outputs the size of all the generated sets of itemsets and the rules.- Overrides:
toString
in classjava.lang.Object
- Returns:
- a string representation of the model
-
metricString
public java.lang.String metricString()
Returns the metric string for the chosen metric type- Specified by:
metricString
in interfaceCARuleMiner
- Returns:
- a string describing the used metric for the interestingness of a class association rule
-
removeAllMissingColsTipText
public java.lang.String removeAllMissingColsTipText()
Returns the tip text for this property- Returns:
- tip text for this property suitable for displaying in the explorer/experimenter gui
-
setRemoveAllMissingCols
public void setRemoveAllMissingCols(boolean r)
Remove columns containing all missing values.- Parameters:
r
- true if cols are to be removed.
-
getRemoveAllMissingCols
public boolean getRemoveAllMissingCols()
Returns whether columns containing all missing values are to be removed- Returns:
- true if columns are to be removed.
-
upperBoundMinSupportTipText
public java.lang.String upperBoundMinSupportTipText()
Returns the tip text for this property- Returns:
- tip text for this property suitable for displaying in the explorer/experimenter gui
-
getUpperBoundMinSupport
public double getUpperBoundMinSupport()
Get the value of upperBoundMinSupport.- Returns:
- Value of upperBoundMinSupport.
-
setUpperBoundMinSupport
public void setUpperBoundMinSupport(double v)
Set the value of upperBoundMinSupport.- Parameters:
v
- Value to assign to upperBoundMinSupport.
-
setClassIndex
public void setClassIndex(int index)
Sets the class index- Specified by:
setClassIndex
in interfaceCARuleMiner
- Parameters:
index
- the class index
-
getClassIndex
public int getClassIndex()
Gets the class index- Returns:
- the index of the class attribute
-
classIndexTipText
public java.lang.String classIndexTipText()
Returns the tip text for this property- Returns:
- tip text for this property suitable for displaying in the explorer/experimenter gui
-
setCar
public void setCar(boolean flag)
Sets class association rule mining- Parameters:
flag
- if class association rules are mined, false otherwise
-
getCar
public boolean getCar()
Gets whether class association ruels are mined- Returns:
- true if class association rules are mined, false otherwise
-
carTipText
public java.lang.String carTipText()
Returns the tip text for this property- Returns:
- tip text for this property suitable for displaying in the explorer/experimenter gui
-
lowerBoundMinSupportTipText
public java.lang.String lowerBoundMinSupportTipText()
Returns the tip text for this property- Returns:
- tip text for this property suitable for displaying in the explorer/experimenter gui
-
getLowerBoundMinSupport
public double getLowerBoundMinSupport()
Get the value of lowerBoundMinSupport.- Returns:
- Value of lowerBoundMinSupport.
-
setLowerBoundMinSupport
public void setLowerBoundMinSupport(double v)
Set the value of lowerBoundMinSupport.- Parameters:
v
- Value to assign to lowerBoundMinSupport.
-
getMetricType
public SelectedTag getMetricType()
Get the metric type- Returns:
- the type of metric to use for ranking rules
-
metricTypeTipText
public java.lang.String metricTypeTipText()
Returns the tip text for this property- Returns:
- tip text for this property suitable for displaying in the explorer/experimenter gui
-
setMetricType
public void setMetricType(SelectedTag d)
Set the metric type for ranking rules- Parameters:
d
- the type of metric
-
minMetricTipText
public java.lang.String minMetricTipText()
Returns the tip text for this property- Returns:
- tip text for this property suitable for displaying in the explorer/experimenter gui
-
getMinMetric
public double getMinMetric()
Get the value of minConfidence.- Returns:
- Value of minConfidence.
-
setMinMetric
public void setMinMetric(double v)
Set the value of minConfidence.- Parameters:
v
- Value to assign to minConfidence.
-
numRulesTipText
public java.lang.String numRulesTipText()
Returns the tip text for this property- Returns:
- tip text for this property suitable for displaying in the explorer/experimenter gui
-
getNumRules
public int getNumRules()
Get the value of numRules.- Returns:
- Value of numRules.
-
setNumRules
public void setNumRules(int v)
Set the value of numRules.- Parameters:
v
- Value to assign to numRules.
-
deltaTipText
public java.lang.String deltaTipText()
Returns the tip text for this property- Returns:
- tip text for this property suitable for displaying in the explorer/experimenter gui
-
getDelta
public double getDelta()
Get the value of delta.- Returns:
- Value of delta.
-
setDelta
public void setDelta(double v)
Set the value of delta.- Parameters:
v
- Value to assign to delta.
-
significanceLevelTipText
public java.lang.String significanceLevelTipText()
Returns the tip text for this property- Returns:
- tip text for this property suitable for displaying in the explorer/experimenter gui
-
getSignificanceLevel
public double getSignificanceLevel()
Get the value of significanceLevel.- Returns:
- Value of significanceLevel.
-
setSignificanceLevel
public void setSignificanceLevel(double v)
Set the value of significanceLevel.- Parameters:
v
- Value to assign to significanceLevel.
-
setOutputItemSets
public void setOutputItemSets(boolean flag)
Sets whether itemsets are output as well- Parameters:
flag
- true if itemsets are to be output as well
-
getOutputItemSets
public boolean getOutputItemSets()
Gets whether itemsets are output as well- Returns:
- true if itemsets are output as well
-
outputItemSetsTipText
public java.lang.String outputItemSetsTipText()
Returns the tip text for this property- Returns:
- tip text for this property suitable for displaying in the explorer/experimenter gui
-
setVerbose
public void setVerbose(boolean flag)
Sets verbose mode- Parameters:
flag
- true if algorithm should be run in verbose mode
-
getVerbose
public boolean getVerbose()
Gets whether algorithm is run in verbose mode- Returns:
- true if algorithm is run in verbose mode
-
verboseTipText
public java.lang.String verboseTipText()
Returns the tip text for this property- Returns:
- tip text for this property suitable for displaying in the explorer/experimenter gui
-
getAllTheRules
public FastVector[] getAllTheRules()
returns all the rules- Returns:
- all the rules
- See Also:
m_allTheRules
-
getRevision
public java.lang.String getRevision()
Returns the revision string.- Specified by:
getRevision
in interfaceRevisionHandler
- Overrides:
getRevision
in classAbstractAssociator
- Returns:
- the revision
-
main
public static void main(java.lang.String[] args)
Main method.- Parameters:
args
- the commandline options
-
-