Class 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 Detail

      • TAGS_SELECTION

        public static final Tag[] TAGS_SELECTION
        Metric types.
    • Constructor Detail

      • Apriori

        public Apriori()
        Constructor that allows to sets default values for the minimum confidence and the maximum number of rules the minimum confidence.
    • 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 interface TechnicalInformationHandler
        Returns:
        the technical information about this class
      • resetOptions

        public void resetOptions()
        Resets the options to the default values.
      • 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 interface Associator
        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 interface CARuleMiner
        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 interface CARuleMiner
        Returns:
        the instances without the class attribute.
      • getInstancesOnlyClass

        public Instances getInstancesOnlyClass()
        Gets only the class attribute of the instances.
        Specified by:
        getInstancesOnlyClass in interface CARuleMiner
        Returns:
        the class attribute of all instances.
      • listOptions

        public java.util.Enumeration listOptions()
        Returns an enumeration describing the available options.
        Specified by:
        listOptions in interface OptionHandler
        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 interface OptionHandler
        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 interface OptionHandler
        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 class java.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 interface CARuleMiner
        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 interface CARuleMiner
        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
      • main

        public static void main​(java.lang.String[] args)
        Main method.
        Parameters:
        args - the commandline options