weka.classifiers.functions

## Class LinearRegression

- java.lang.Object
- - weka.classifiers.AbstractClassifier
  - - weka.classifiers.functions.LinearRegression

- All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable, Classifier, BatchPredictor, CapabilitiesHandler, CapabilitiesIgnorer, CommandlineRunnable, OptionHandler, RevisionHandler, WeightedInstancesHandler

      public class LinearRegression
      extends AbstractClassifier
      implements OptionHandler, WeightedInstancesHandler

  Class for using linear regression for prediction. Uses the Akaike criterion for model selection, and is able to deal with weighted instances.

  Valid options are:

       -S <number of selection method>
        Set the attribute selection method to use. 1 = None, 2 = Greedy.
        (default 0 = M5' method)

       -C
        Do not try to eliminate colinear attributes.

       -R <double>
        Set ridge parameter (default 1.0e-8).

       -minimal
        Conserve memory, don't keep dataset header and means/stdevs.
        Model cannot be printed out if this option is enabled. (default: keep data)

       -additional-stats
        Output additional statistics.

       -output-debug-info
        If set, classifier is run in debug mode and
        may output additional info to the console

       -do-not-check-capabilities
        If set, classifier capabilities are not checked before classifier is built
        (use with caution).

       -do-not-check-capabilities
        If set, classifier capabilities are not checked before classifier is built
        (use with caution).

  Version:
    $Revision: 14873 $
  Author:
    Eibe Frank (eibe@cs.waikato.ac.nz), Len Trigg (trigg@cs.waikato.ac.nz)
  See Also:
    Serialized Form

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static int` | `SELECTION_GREEDY` Attribute selection method: Greedy method
    `static int` | `SELECTION_M5` Attribute selection method: M5 method
    `static int` | `SELECTION_NONE` Attribute selection method: No attribute selection
    `static Tag[]` | `TAGS_SELECTION` Attribute selection methods

    - ### Fields inherited from class weka.classifiers.AbstractClassifier

      `BATCH_SIZE_DEFAULT, NUM_DECIMAL_PLACES_DEFAULT`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `LinearRegression()`

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `java.lang.String` | `attributeSelectionMethodTipText()` Returns the tip text for this property
    `void` | `buildClassifier(Instances data)` Builds a regression model for the given data.
    `double` | `classifyInstance(Instance instance)` Classifies the given instance using the linear regression function.
    `double[]` | `coefficients()` Returns the coefficients for this linear model.
    `java.lang.String` | `eliminateColinearAttributesTipText()` Returns the tip text for this property
    `SelectedTag` | `getAttributeSelectionMethod()` Gets the method used to select attributes for use in the linear regression.
    `Capabilities` | `getCapabilities()` Returns default capabilities of the classifier.
    `boolean` | `getEliminateColinearAttributes()` Get the value of EliminateColinearAttributes.
    `boolean` | `getMinimal()` Returns whether to be more memory conservative or being able to output the model as string.
    `java.lang.String[]` | `getOptions()` Gets the current settings of the classifier.
    `boolean` | `getOutputAdditionalStats()` Get whether to output additional statistics (such as std.
    `java.lang.String` | `getRevision()` Returns the revision string.
    `double` | `getRidge()` Get the value of Ridge.
    `boolean` | `getUseQRDecomposition()` Get whether to use QR decomposition.
    `java.lang.String` | `globalInfo()` Returns a string describing this classifier
    `java.util.Enumeration<Option>` | `listOptions()` Returns an enumeration describing the available options.
    `static void` | `main(java.lang.String[] argv)` Generates a linear regression function predictor.
    `java.lang.String` | `minimalTipText()` Returns the tip text for this property.
    `int` | `numParameters()` Get the number of coefficients used in the model
    `java.lang.String` | `outputAdditionalStatsTipText()` Returns the tip text for this property.
    `java.lang.String` | `ridgeTipText()` Returns the tip text for this property
    `void` | `setAttributeSelectionMethod(SelectedTag method)` Sets the method used to select attributes for use in the linear regression.
    `void` | `setEliminateColinearAttributes(boolean newEliminateColinearAttributes)` Set the value of EliminateColinearAttributes.
    `void` | `setMinimal(boolean value)` Sets whether to be more memory conservative or being able to output the model as string.
    `void` | `setOptions(java.lang.String[] options)` Parses a given list of options.
    `void` | `setOutputAdditionalStats(boolean additional)` Set whether to output additional statistics (such as std.
    `void` | `setRidge(double newRidge)` Set the value of Ridge.
    `void` | `setUseQRDecomposition(boolean useQR)` Set whether to use QR decomposition.
    `java.lang.String` | `toString()` Outputs the linear regression model as a string.
    `void` | `turnChecksOff()` Turns off checks for missing values, etc.
    `void` | `turnChecksOn()` Turns on checks for missing values, etc.
    `java.lang.String` | `useQRDecompositionTipText()` Returns the tip text for this property.

    - ### Methods inherited from class weka.classifiers.AbstractClassifier

      `batchSizeTipText, debugTipText, distributionForInstance, distributionsForInstances, doNotCheckCapabilitiesTipText, forName, getBatchSize, getDebug, getDoNotCheckCapabilities, getNumDecimalPlaces, implementsMoreEfficientBatchPrediction, makeCopies, makeCopy, numDecimalPlacesTipText, postExecution, preExecution, run, runClassifier, setBatchSize, setDebug, setDoNotCheckCapabilities, setNumDecimalPlaces`

    - ### Methods inherited from class java.lang.Object

      `equals, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- - ### Field Detail

    - #### SELECTION_M5

          public static final int SELECTION_M5

      Attribute selection method: M5 method
      See Also:
        Constant Field Values

    - #### SELECTION_NONE

          public static final int SELECTION_NONE

      Attribute selection method: No attribute selection
      See Also:
        Constant Field Values

    - #### SELECTION_GREEDY

          public static final int SELECTION_GREEDY

      Attribute selection method: Greedy method
      See Also:
        Constant Field Values

    - #### TAGS_SELECTION

          public static final Tag[] TAGS_SELECTION

      Attribute selection methods

  - ### Constructor Detail

    - #### LinearRegression

          public LinearRegression()

  - ### Method Detail

    - #### main

          public static void main(java.lang.String[] argv)

      Generates a linear regression function predictor.
      Parameters:
        `argv` - the options

    - #### globalInfo

          public java.lang.String globalInfo()

      Returns a string describing this classifier
      Returns:
        a description of the classifier suitable for displaying in the explorer/experimenter gui

    - #### getCapabilities

          public Capabilities getCapabilities()

      Returns default capabilities of the classifier.
      Specified by:
        `getCapabilities` in interface `Classifier`
      Specified by:
        `getCapabilities` in interface `CapabilitiesHandler`
      Overrides:
        `getCapabilities` in class `AbstractClassifier`
      Returns:
        the capabilities of this classifier
      See Also:
        `Capabilities`

    - #### buildClassifier

          public void buildClassifier(Instances data)
                               throws java.lang.Exception

      Builds a regression model for the given data.
      Specified by:
        `buildClassifier` in interface `Classifier`
      Parameters:
        `data` - the training data to be used for generating the linear regression function
      Throws:
        `java.lang.Exception` - if the classifier could not be built successfully

    - #### classifyInstance

          public double classifyInstance(Instance instance)
                                  throws java.lang.Exception

      Classifies the given instance using the linear regression function.
      Specified by:
        `classifyInstance` in interface `Classifier`
      Overrides:
        `classifyInstance` in class `AbstractClassifier`
      Parameters:
        `instance` - the test instance
      Returns:
        the classification
      Throws:
        `java.lang.Exception` - if classification can't be done successfully

    - #### toString

          public java.lang.String toString()

      Outputs the linear regression model as a string.
      Overrides:
        `toString` in class `java.lang.Object`
      Returns:
        the model as string

    - #### listOptions

          public java.util.Enumeration<Option> 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.

    - #### coefficients

          public double[] coefficients()

      Returns the coefficients for this linear model.
      Returns:
        the coefficients for this linear model

    - #### 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

    - #### setOptions

          public void setOptions(java.lang.String[] options)
                          throws java.lang.Exception

      Parses a given list of options.

      Valid options are:

           -S <number of selection method>
            Set the attribute selection method to use. 1 = None, 2 = Greedy.
            (default 0 = M5' method)

           -C
            Do not try to eliminate colinear attributes.

           -R <double>
            Set ridge parameter (default 1.0e-8).

           -minimal
            Conserve memory, don't keep dataset header and means/stdevs.
            Model cannot be printed out if this option is enabled. (default: keep data)

           -additional-stats
            Output additional statistics.

           -output-debug-info
            If set, classifier is run in debug mode and
            may output additional info to the console

           -do-not-check-capabilities
            If set, classifier capabilities are not checked before classifier is built
            (use with caution).

           -use-qr
            If set, QR decomposition will be used to find coefficients.

      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

    - #### ridgeTipText

          public java.lang.String ridgeTipText()

      Returns the tip text for this property
      Returns:
        tip text for this property suitable for displaying in the explorer/experimenter gui

    - #### getRidge

          public double getRidge()

      Get the value of Ridge.
      Returns:
        Value of Ridge.

    - #### setRidge

          public void setRidge(double newRidge)

      Set the value of Ridge.
      Parameters:
        `newRidge` - Value to assign to Ridge.

    - #### eliminateColinearAttributesTipText

          public java.lang.String eliminateColinearAttributesTipText()

      Returns the tip text for this property
      Returns:
        tip text for this property suitable for displaying in the explorer/experimenter gui

    - #### getEliminateColinearAttributes

          public boolean getEliminateColinearAttributes()

      Get the value of EliminateColinearAttributes.
      Returns:
        Value of EliminateColinearAttributes.

    - #### setEliminateColinearAttributes

          public void setEliminateColinearAttributes(boolean newEliminateColinearAttributes)

      Set the value of EliminateColinearAttributes.
      Parameters:
        `newEliminateColinearAttributes` - Value to assign to EliminateColinearAttributes.

    - #### numParameters

          public int numParameters()

      Get the number of coefficients used in the model
      Returns:
        the number of coefficients

    - #### attributeSelectionMethodTipText

          public java.lang.String attributeSelectionMethodTipText()

      Returns the tip text for this property
      Returns:
        tip text for this property suitable for displaying in the explorer/experimenter gui

    - #### getAttributeSelectionMethod

          public SelectedTag getAttributeSelectionMethod()

      Gets the method used to select attributes for use in the linear regression.
      Returns:
        the method to use.

    - #### setAttributeSelectionMethod

          public void setAttributeSelectionMethod(SelectedTag method)

      Sets the method used to select attributes for use in the linear regression.
      Parameters:
        `method` - the attribute selection method to use.

    - #### minimalTipText

          public java.lang.String minimalTipText()

      Returns the tip text for this property.
      Returns:
        tip text for this property suitable for displaying in the explorer/experimenter gui

    - #### getMinimal

          public boolean getMinimal()

      Returns whether to be more memory conservative or being able to output the model as string.
      Returns:
        true if memory conservation is preferred over outputting model description

    - #### setMinimal

          public void setMinimal(boolean value)

      Sets whether to be more memory conservative or being able to output the model as string.
      Parameters:
        `value` - if true memory will be conserved

    - #### outputAdditionalStatsTipText

          public java.lang.String outputAdditionalStatsTipText()

      Returns the tip text for this property.
      Returns:
        tip text for this property suitable for displaying in the explorer/experimenter gui

    - #### getOutputAdditionalStats

          public boolean getOutputAdditionalStats()

      Get whether to output additional statistics (such as std. deviation of coefficients and t-statistics
      Returns:
        true if additional stats are to be output

    - #### setOutputAdditionalStats

          public void setOutputAdditionalStats(boolean additional)

      Set whether to output additional statistics (such as std. deviation of coefficients and t-statistics
      Parameters:
        `additional` - true if additional stats are to be output

    - #### useQRDecompositionTipText

          public java.lang.String useQRDecompositionTipText()

      Returns the tip text for this property.
      Returns:
        tip text for this property suitable for displaying in the explorer/experimenter gui

    - #### getUseQRDecomposition

          public boolean getUseQRDecomposition()

      Get whether to use QR decomposition.
      Returns:
        true if QR decomposition is to be used

    - #### setUseQRDecomposition

          public void setUseQRDecomposition(boolean useQR)

      Set whether to use QR decomposition.
      Parameters:
        `useQR` - true if QR decomposition is to be used

    - #### turnChecksOff

          public void turnChecksOff()

      Turns off checks for missing values, etc. Use with caution. Also turns off scaling.

    - #### turnChecksOn

          public void turnChecksOn()

      Turns on checks for missing values, etc. Also turns on scaling.

    - #### getRevision

          public java.lang.String getRevision()

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