Package weka.classifiers.functions
Class LinearRegression
java.lang.Object
weka.classifiers.Classifier
weka.classifiers.functions.LinearRegression
- All Implemented Interfaces:
Serializable,Cloneable,CapabilitiesHandler,OptionHandler,RevisionHandler,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:
-D Produce debugging output. (default no debugging output)
-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).
- Version:
- $Revision: 9770 $
- Author:
- Eibe Frank (eibe@cs.waikato.ac.nz), Len Trigg (trigg@cs.waikato.ac.nz)
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intAttribute selection method: Greedy methodstatic final intAttribute selection method: M5 methodstatic final intAttribute selection method: No attribute selectionstatic final Tag[]Attribute selection methods -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionReturns the tip text for this propertyvoidbuildClassifier(Instances data) Builds a regression model for the given data.doubleclassifyInstance(Instance instance) Classifies the given instance using the linear regression function.double[]Returns the coefficients for this linear model.Returns the tip text for this propertyReturns the tip text for this propertyGets the method used to select attributes for use in the linear regression.Returns default capabilities of the classifier.booleangetDebug()Controls whether debugging output will be printedbooleanGet the value of EliminateColinearAttributes.String[]Gets the current settings of the classifier.Returns the revision string.doublegetRidge()Get the value of Ridge.Returns a string describing this classifierReturns an enumeration describing the available options.static voidGenerates a linear regression function predictor.intGet the number of coefficients used in the modelReturns the tip text for this propertyvoidSets the method used to select attributes for use in the linear regression.voidsetDebug(boolean debug) Controls whether debugging output will be printedvoidsetEliminateColinearAttributes(boolean newEliminateColinearAttributes) Set the value of EliminateColinearAttributes.voidsetOptions(String[] options) Parses a given list of options.voidsetRidge(double newRidge) Set the value of Ridge.toString()Outputs the linear regression model as a string.voidTurns off checks for missing values, etc.voidTurns on checks for missing values, etc.Methods inherited from class weka.classifiers.Classifier
distributionForInstance, forName, makeCopies, makeCopy
-
Field Details
-
SELECTION_M5
public static final int SELECTION_M5Attribute selection method: M5 method- See Also:
-
SELECTION_NONE
public static final int SELECTION_NONEAttribute selection method: No attribute selection- See Also:
-
SELECTION_GREEDY
public static final int SELECTION_GREEDYAttribute selection method: Greedy method- See Also:
-
TAGS_SELECTION
Attribute selection methods
-
-
Constructor Details
-
LinearRegression
public LinearRegression()
-
-
Method Details
-
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. -
globalInfo
Returns a string describing this classifier- Returns:
- a description of the classifier suitable for displaying in the explorer/experimenter gui
-
getCapabilities
Returns default capabilities of the classifier.- Specified by:
getCapabilitiesin interfaceCapabilitiesHandler- Overrides:
getCapabilitiesin classClassifier- Returns:
- the capabilities of this classifier
- See Also:
-
buildClassifier
Builds a regression model for the given data.- Specified by:
buildClassifierin classClassifier- Parameters:
data- the training data to be used for generating the linear regression function- Throws:
Exception- if the classifier could not be built successfully
-
classifyInstance
Classifies the given instance using the linear regression function.- Overrides:
classifyInstancein classClassifier- Parameters:
instance- the test instance- Returns:
- the classification
- Throws:
Exception- if classification can't be done successfully
-
toString
Outputs the linear regression model as a string. -
listOptions
Returns an enumeration describing the available options.- Specified by:
listOptionsin interfaceOptionHandler- Overrides:
listOptionsin classClassifier- Returns:
- an enumeration of all the available options.
-
setOptions
Parses a given list of options. Valid options are:-D Produce debugging output. (default no debugging output)
-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).
- Specified by:
setOptionsin interfaceOptionHandler- Overrides:
setOptionsin classClassifier- Parameters:
options- the list of options as an array of strings- Throws:
Exception- if an option is not supported
-
coefficients
public double[] coefficients()Returns the coefficients for this linear model.- Returns:
- the coefficients for this linear model
-
getOptions
Gets the current settings of the classifier.- Specified by:
getOptionsin interfaceOptionHandler- Overrides:
getOptionsin classClassifier- Returns:
- an array of strings suitable for passing to setOptions
-
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
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
Returns the tip text for this property- Returns:
- tip text for this property suitable for displaying in the explorer/experimenter gui
-
setAttributeSelectionMethod
Sets the method used to select attributes for use in the linear regression.- Parameters:
method- the attribute selection method to use.
-
getAttributeSelectionMethod
Gets the method used to select attributes for use in the linear regression.- Returns:
- the method to use.
-
debugTipText
Returns the tip text for this property- Overrides:
debugTipTextin classClassifier- Returns:
- tip text for this property suitable for displaying in the explorer/experimenter gui
-
setDebug
public void setDebug(boolean debug) Controls whether debugging output will be printed- Overrides:
setDebugin classClassifier- Parameters:
debug- true if debugging output should be printed
-
getDebug
public boolean getDebug()Controls whether debugging output will be printed- Overrides:
getDebugin classClassifier- Returns:
- true if debugging output is printed
-
getRevision
Returns the revision string.- Specified by:
getRevisionin interfaceRevisionHandler- Overrides:
getRevisionin classClassifier- Returns:
- the revision
-
main
Generates a linear regression function predictor.- Parameters:
argv- the options
-