weka.classifiers.rules.car
Class WeightedClassifier

java.lang.Object
  extended by weka.classifiers.AbstractClassifier
      extended by weka.classifiers.rules.car.CarClassifier
          extended by weka.classifiers.rules.car.WeightedClassifier
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, Classifier, AdditionalMeasureProducer, CapabilitiesHandler, OptionHandler, RevisionHandler

public class WeightedClassifier
extends CarClassifier
implements OptionHandler, AdditionalMeasureProducer, CapabilitiesHandler

Class implemting three different weighted classifiers for class association rules. a) all rules are weighted equally with weight one (default behaviour). b) all rules are weighted linearly c) all rules are weighted using the inverse function 1/position in sort order of mining algorithm The pruning step is omitted. All mined rules are used for classifcation, if not specified otherwise with the -L option. Valid options are:

-A Class Association Rule Miner String
Class Association Rule Miner String should contain the full class name of a scheme included for selection followed by options to the Class Association Rule Miner.

-W weighting scheme
Sets the weighting scheme: inverse|linear|equal (default).

-L rule limit
Set a rule limit for the number of rules used for classification after the pruning step. Uses the first N rules only.

Version:
$Revision: 8108 $
Author:
Stefan Mutter
See Also:
Serialized Form

Field Summary
static Tag[] TAGS_SELECTION
           
 
Constructor Summary
WeightedClassifier()
           
 
Method Summary
 void buildClassifier(Instances newInstances)
          Generates the classifier.
 java.lang.String carMinerTipText()
          Gets the tipText for this option.
 double[] distributionForInstance(Instance newInstance)
          Returns the class distribution for an instance
 java.util.Enumeration enumerateMeasures()
          Lists all additional statistics that are available
 Capabilities getCapabilities()
          Returns default capabilities of the base associator.
 CARuleMiner getCarMiner()
          Gets the class association rule miner
 double getMeasure(java.lang.String additionalMeasureName)
          Gets the additional statistics
 java.lang.String[] getOptions()
          Gets the current settings of the Classifier.
 PruneCAR getPrune()
          Gets the pruning algorithm: PrecedencePruning
 java.lang.String getRevision()
          Returns the revision string.
 int getRuleLimit()
          Gets the rule limit (-1 means no limit)
 SelectedTag getWeightScheme()
          Gets the type of the weighting scheme
 java.lang.String globalInfo()
          Gets a description of WeightedClassifier
 java.util.Enumeration listOptions()
          Returns an enumeration describing the available options
static void main(java.lang.String[] argv)
          Main method for testing this class.
 double measureAverageRankCorrect()
          Gets the average rank of the first rule that covers an instance.
 double measureAverageRankFires()
          Gets the average rank of the first rule that covers an instance and predicts it correctly.
 double measureMiningTime()
          Gets the mining time
 double measureNumClassRules()
          Gets the number of rules used for classification
 double measureNumMinedRules()
          Gets the number of mined rules
 double measureNumPrunedRules()
          Gets the number of rules after the optional pruning step
 double measurePruningTime()
          Gets the pruning time in seconds
 java.lang.String ruleLimitTipText()
          Gets the tipText for this option.
 void setCarMiner(CARuleMiner assoc)
          Sets the class association rule miner
 void setOptions(java.lang.String[] options)
          Parses a given list of options.
 void setRuleLimit(int n)
          Sets a rule limit.
 void setWeightScheme(SelectedTag type)
          Sets the weighting scheme
 java.lang.String toString()
          Prints the rules
 double weight(java.lang.String type, double rank)
          Weights a rule
 java.lang.String weightSchemeTipText()
          Gets the tipText for this option.
 
Methods inherited from class weka.classifiers.rules.car.CarClassifier
sortAttributes
 
Methods inherited from class weka.classifiers.AbstractClassifier
classifyInstance, debugTipText, forName, getDebug, makeCopies, makeCopy, runClassifier, setDebug
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

TAGS_SELECTION

public static final Tag[] TAGS_SELECTION
Constructor Detail

WeightedClassifier

public WeightedClassifier()
Method Detail

getCapabilities

public Capabilities getCapabilities()
Returns default capabilities of the base associator.

Specified by:
getCapabilities in interface Classifier
Specified by:
getCapabilities in interface CapabilitiesHandler
Overrides:
getCapabilities in class AbstractClassifier
Returns:
the capabilities of the base classifier

globalInfo

public java.lang.String globalInfo()
Gets a description of WeightedClassifier

Returns:
a description of WeightedClassifier

listOptions

public java.util.Enumeration listOptions()
Returns an enumeration describing the available options

Specified by:
listOptions in interface OptionHandler
Overrides:
listOptions in class AbstractClassifier
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:

-A Class Association Rule Miner String
Class Association Rule Miner String should contain the full class name of a scheme included for selection followed by options to the Class Association Rule Miner.

-W weighting scheme
Sets the weighting scheme: inverse|linear|equal (default).

-L rule limit
Set a rule limit for the number of rules used for classification after the pruning step. Uses the first N rules only.

Specified by:
setOptions in interface OptionHandler
Overrides:
setOptions in class AbstractClassifier
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 Classifier.

Specified by:
getOptions in interface OptionHandler
Overrides:
getOptions in class AbstractClassifier
Returns:
an array of strings suitable for passing to setOptions

carMinerTipText

public java.lang.String carMinerTipText()
Gets the tipText for this option.

Returns:
the tipText for this option.

setCarMiner

public void setCarMiner(CARuleMiner assoc)
Sets the class association rule miner

Parameters:
assoc - the class association rule miner

getCarMiner

public CARuleMiner getCarMiner()
Gets the class association rule miner

Returns:
the class association rule miner

getPrune

public PruneCAR getPrune()
Gets the pruning algorithm: PrecedencePruning

Returns:
the pruning algorithm

buildClassifier

public void buildClassifier(Instances newInstances)
                     throws java.lang.Exception
Generates the classifier.

Specified by:
buildClassifier in interface Classifier
Parameters:
newInstances - set of instances serving as training data
Throws:
java.lang.Exception - if the classifier has not been generated successfully

distributionForInstance

public double[] distributionForInstance(Instance newInstance)
                                 throws java.lang.Exception
Returns the class distribution for an instance

Specified by:
distributionForInstance in interface Classifier
Overrides:
distributionForInstance in class AbstractClassifier
Parameters:
newInstance - the instance
Returns:
the class distribution
Throws:
java.lang.Exception - exception if it cannot be calculated

weightSchemeTipText

public java.lang.String weightSchemeTipText()
Gets the tipText for this option.

Returns:
the tipText for this option.

setWeightScheme

public void setWeightScheme(SelectedTag type)
Sets the weighting scheme

Parameters:
type - the type of the weighting scheme: inverse | linear | equal

getWeightScheme

public SelectedTag getWeightScheme()
Gets the type of the weighting scheme

Returns:
type of the weighting scheme: inverse | linear | equal

ruleLimitTipText

public java.lang.String ruleLimitTipText()
Gets the tipText for this option.

Returns:
the tipText for this option.

setRuleLimit

public void setRuleLimit(int n)
Sets a rule limit. Only the first n rules after pruning are then used for classification (-1 means no limit).

Parameters:
n - the rule limit

getRuleLimit

public int getRuleLimit()
Gets the rule limit (-1 means no limit)

Returns:
the rule limit

weight

public double weight(java.lang.String type,
                     double rank)
Weights a rule

Parameters:
type - the weighting scheme
rank - the rank of the rule in the sort order
Returns:
the weight of a rule

toString

public java.lang.String toString()
Prints the rules

Overrides:
toString in class java.lang.Object
Returns:
the rules

enumerateMeasures

public java.util.Enumeration enumerateMeasures()
Lists all additional statistics that are available

Specified by:
enumerateMeasures in interface AdditionalMeasureProducer
Returns:
list of the names of the additional measures

getMeasure

public double getMeasure(java.lang.String additionalMeasureName)
Gets the additional statistics

Specified by:
getMeasure in interface AdditionalMeasureProducer
Parameters:
additionalMeasureName - the name of the additional measure
Returns:
the value of the measure

measureMiningTime

public double measureMiningTime()
Gets the mining time

Returns:
the mining time in seconds

measurePruningTime

public double measurePruningTime()
Gets the pruning time in seconds

Returns:
the pruning time in seconds

measureNumMinedRules

public double measureNumMinedRules()
Gets the number of mined rules

Returns:
the number of mined rules

measureNumPrunedRules

public double measureNumPrunedRules()
Gets the number of rules after the optional pruning step

Returns:
the number of rules after the optional pruning step

measureNumClassRules

public double measureNumClassRules()
Gets the number of rules used for classification

Returns:
the number of rules used for classification

measureAverageRankFires

public double measureAverageRankFires()
Gets the average rank of the first rule that covers an instance and predicts it correctly.

Returns:
the average rank of the first rule that covers an instance and predicts it correctly.

measureAverageRankCorrect

public double measureAverageRankCorrect()
Gets the average rank of the first rule that covers an instance.

Returns:
the average rank of the first rule that covers an instance.

getRevision

public java.lang.String getRevision()
Returns the revision string.

Specified by:
getRevision in interface RevisionHandler
Overrides:
getRevision in class AbstractClassifier
Returns:
the revision

main

public static void main(java.lang.String[] argv)
Main method for testing this class.

Parameters:
argv - the options