Class ClassConditionalProbabilities

  • All Implemented Interfaces:
    java.io.Serializable, CapabilitiesHandler, CapabilitiesIgnorer, CommandlineRunnable, OptionHandler, RevisionHandler, WeightedAttributesHandler, WeightedInstancesHandler

    public class ClassConditionalProbabilities
    extends SimpleBatchFilter
    implements WeightedAttributesHandler, WeightedInstancesHandler
    Converts the values of nominal and/or numeric attributes into class conditional probabilities. If there are k classes, then k new attributes are created for each of the original ones, giving pr(att val | class k).

    Can be useful for converting nominal attributes with a lot of distinct values into something more manageable for learning schemes that can't handle nominal attributes (as opposed to creating binary indicator attributes). For nominal attributes, the user can specify the number values above which an attribute will be converted by this method. Normal distributions are assumed for numeric attributes.

    Valid options are:

     -N
      Don't apply this transformation to numeric attributes
     -C
      Don't apply this transformation to nominal attributes
     -min-values <integer>
      Transform nominal attributes with at least this many values.
      -1 means always transform.
     -output-debug-info
      If set, filter is run in debug mode and
      may output additional info to the console
     -do-not-check-capabilities
      If set, filter capabilities are not checked before filter is built
      (use with caution).
    -spread-attribute-weight
      When generating binary attributes, spread weight of old
      attribute across new attributes. Do not give each new attribute the old weight.
    Version:
    $Revision: $
    Author:
    Mark Hall (mhall{[at]}pentaho{[dot]}com)
    See Also:
    Serialized Form
    • Constructor Detail

      • ClassConditionalProbabilities

        public ClassConditionalProbabilities()
    • Method Detail

      • main

        public static void main​(java.lang.String[] args)
        Main method for testing this class
        Parameters:
        args - args
      • globalInfo

        public java.lang.String globalInfo()
        Global help info for this method
        Specified by:
        globalInfo in class SimpleFilter
        Returns:
        the global help info
      • setExcludeNumericAttributes

        public void setExcludeNumericAttributes​(boolean e)
        Set whether numeric attributes are being excluded from the transformation
        Parameters:
        e - true if numeric attributes are to be excluded
      • setExcludeNominalAttributes

        public void setExcludeNominalAttributes​(boolean e)
        Set whether nominal attributes are to be excluded from the transformation
        Parameters:
        e - true if nominal attributes are to be excluded
      • setSpreadAttributeWeight

        @OptionMetadata(displayName="Spread weight across new attributes",
                        description="When generating attributes, spread weight of old\nattribute across new attributes. Do not give each new attribute the old weight.",
                        commandLineParamName="spread-attribute-weight",
                        commandLineParamIsFlag=true,
                        commandLineParamSynopsis="-spread-attribute-weight",
                        displayOrder=3)
        public void setSpreadAttributeWeight​(boolean p)
        If true, when generating attributes, spread weight of old attribute across new attributes. Do not give each new attribute the old weight.
        Parameters:
        p - whether weight is spread
      • getSpreadAttributeWeight

        public boolean getSpreadAttributeWeight()
        If true, when generating attributes, spread weight of old attribute across new attributes. Do not give each new attribute the old weight.
        Returns:
        whether weight is spread
      • getNominalConversionThreshold

        @OptionMetadata(displayName="Nominal conversion threshold",
                        description="Transform nominal attributes with at least this many values.\n-1 means always transform.",
                        commandLineParamName="min-values",
                        commandLineParamSynopsis="-min-values <integer>",
                        displayOrder=3)
        public int getNominalConversionThreshold()
        Get the minimum number of values a nominal attribute must have in order to be transformed. -1 indicates no minimum (i.e. transform all nominal attributes)
        Returns:
        the number of values of a nominal attribute after which the transformation applies
      • setNominalConversionThreshold

        public void setNominalConversionThreshold​(int n)
        Set the minimum number of values a nominal attribute must have in order to be transformed. -1 indicates no minimum (i.e. transform all nominal attributes)
        Parameters:
        n - the number of values of a nominal attribute after which the transformation applies
      • input

        public boolean input​(Instance inst)
                      throws java.lang.Exception
        Description copied from class: SimpleBatchFilter
        Input an instance for filtering. Filter requires all training instances be read before producing output (calling the method batchFinished() makes the data available). If this instance is part of a new batch, m_NewBatch is set to false.
        Overrides:
        input in class SimpleBatchFilter
        Parameters:
        inst - the input instance
        Returns:
        true if the filtered instance may now be collected with output().
        Throws:
        java.lang.IllegalStateException - if no input structure has been defined
        java.lang.Exception - if something goes wrong
        See Also:
        SimpleBatchFilter.batchFinished()
      • setEstimator

        public void setEstimator​(NaiveBayes nb)
        Set the naive Bayes estimator to use
        Parameters:
        nb - the naive Bayes estimator to use
      • setRemoveFilter

        public void setRemoveFilter​(Remove r)