public class LinearRegression extends AbstractClassifier implements OptionHandler, WeightedInstancesHandler
-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).
| Modifier and Type | Field and Description |
|---|---|
protected int |
m_AttributeSelection
The current attribute selection method
|
protected boolean |
m_checksTurnedOff
Turn off all checks and conversions?
|
protected int |
m_ClassIndex
The index of the class attribute
|
protected double |
m_ClassMean
The mean of the class attribute
|
protected double |
m_ClassStdDev
The standard deviations of the class attribute
|
protected double[] |
m_Coefficients
Array for storing coefficients of linear regression.
|
protected boolean |
m_EliminateColinearAttributes
Try to eliminate correlated attributes?
|
protected boolean |
m_isZeroR
True if the model is a zero R one
|
protected double[] |
m_Means
The attributes means
|
protected boolean |
m_Minimal
Conserve memory?
|
protected ReplaceMissingValues |
m_MissingFilter
The filter for removing missing values.
|
protected boolean |
m_ModelBuilt
Model already built?
|
protected boolean |
m_outputAdditionalStats
Whether to output additional statistics such as std. dev. of coefficients and t-stats
|
protected double |
m_Ridge
The ridge parameter
|
protected boolean[] |
m_SelectedAttributes
Which attributes are relevant?
|
protected double[] |
m_StdDevs
The attribute standard deviations
|
protected Instances |
m_TransformedData
Variable for storing transformed training data.
|
protected NominalToBinary |
m_TransformFilter
The filter storing the transformation from nominal to binary attributes.
|
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
|
BATCH_SIZE_DEFAULT, m_BatchSize, m_Debug, m_DoNotCheckCapabilities, m_numDecimalPlaces, NUM_DECIMAL_PLACES_DEFAULT| Constructor and Description |
|---|
LinearRegression() |
| 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.
|
protected double |
calculateSE(boolean[] selectedAttributes,
double[] coefficients)
Calculate the squared error of a regression model on the training data
|
double |
classifyInstance(Instance instance)
Classifies the given instance using the linear regression function.
|
double[] |
coefficients()
Returns the coefficients for this linear model.
|
protected boolean |
deselectColinearAttributes(boolean[] selectedAttributes,
double[] coefficients)
Removes the attribute with the highest standardised coefficient greater than 1.5 from the
selected attributes.
|
protected double[] |
doRegression(boolean[] selectedAttributes)
Calculate a linear regression using the selected attributes
|
java.lang.String |
eliminateColinearAttributesTipText()
Returns the tip text for this property
|
protected void |
findBestModel()
Performs a greedy search for the best regression model using Akaike's criterion.
|
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. deviation of coefficients and
t-statistics
|
java.lang.String |
getRevision()
Returns the revision string.
|
double |
getRidge()
Get the value of Ridge.
|
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.
|
protected double |
regressionPrediction(Instance transformedInstance,
boolean[] selectedAttributes,
double[] coefficients)
Calculate the dependent value for a given instance for a given regression model.
|
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. deviation of coefficients and
t-statistics
|
void |
setRidge(double newRidge)
Set the value of Ridge.
|
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.
|
batchSizeTipText, debugTipText, distributionForInstance, distributionsForInstances, doNotCheckCapabilitiesTipText, forName, getBatchSize, getDebug, getDoNotCheckCapabilities, getNumDecimalPlaces, implementsMoreEfficientBatchPrediction, makeCopies, makeCopy, numDecimalPlacesTipText, postExecution, preExecution, run, runClassifier, setBatchSize, setDebug, setDoNotCheckCapabilities, setNumDecimalPlacespublic static final int SELECTION_M5
public static final int SELECTION_NONE
public static final int SELECTION_GREEDY
public static final Tag[] TAGS_SELECTION
protected double[] m_Coefficients
protected boolean[] m_SelectedAttributes
protected Instances m_TransformedData
protected ReplaceMissingValues m_MissingFilter
protected NominalToBinary m_TransformFilter
protected double m_ClassStdDev
protected double m_ClassMean
protected int m_ClassIndex
protected double[] m_Means
protected double[] m_StdDevs
protected boolean m_outputAdditionalStats
protected int m_AttributeSelection
protected boolean m_EliminateColinearAttributes
protected boolean m_checksTurnedOff
protected double m_Ridge
protected boolean m_Minimal
protected boolean m_ModelBuilt
protected boolean m_isZeroR
public static void main(java.lang.String[] argv)
argv - the optionspublic java.lang.String globalInfo()
public Capabilities getCapabilities()
getCapabilities in interface ClassifiergetCapabilities in interface CapabilitiesHandlergetCapabilities in class AbstractClassifierCapabilitiespublic void buildClassifier(Instances data) throws java.lang.Exception
buildClassifier in interface Classifierdata - the training data to be used for generating the linear regression functionjava.lang.Exception - if the classifier could not be built successfullypublic double classifyInstance(Instance instance) throws java.lang.Exception
classifyInstance in interface ClassifierclassifyInstance in class AbstractClassifierinstance - the test instancejava.lang.Exception - if classification can't be done successfullypublic java.lang.String toString()
toString in class java.lang.Objectpublic java.util.Enumeration<Option> listOptions()
listOptions in interface OptionHandlerlistOptions in class AbstractClassifierpublic double[] coefficients()
public java.lang.String[] getOptions()
getOptions in interface OptionHandlergetOptions in class AbstractClassifierpublic void setOptions(java.lang.String[] options)
throws java.lang.Exception
-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).
setOptions in interface OptionHandlersetOptions in class AbstractClassifieroptions - the list of options as an array of stringsjava.lang.Exception - if an option is not supportedpublic java.lang.String ridgeTipText()
public double getRidge()
public void setRidge(double newRidge)
newRidge - Value to assign to Ridge.public java.lang.String eliminateColinearAttributesTipText()
public boolean getEliminateColinearAttributes()
public void setEliminateColinearAttributes(boolean newEliminateColinearAttributes)
newEliminateColinearAttributes - Value to assign to EliminateColinearAttributes.public int numParameters()
public java.lang.String attributeSelectionMethodTipText()
public SelectedTag getAttributeSelectionMethod()
public void setAttributeSelectionMethod(SelectedTag method)
method - the attribute selection method to use.public java.lang.String minimalTipText()
public boolean getMinimal()
public void setMinimal(boolean value)
value - if true memory will be conservedpublic java.lang.String outputAdditionalStatsTipText()
public boolean getOutputAdditionalStats()
public void setOutputAdditionalStats(boolean additional)
additional - true if additional stats are to be outputpublic void turnChecksOff()
public void turnChecksOn()
protected boolean deselectColinearAttributes(boolean[] selectedAttributes,
double[] coefficients)
selectedAttributes - an array of flags indicating which attributes are included in the regression modelcoefficients - an array of coefficients for the regression modelprotected void findBestModel()
throws java.lang.Exception
java.lang.Exception - if regression can't be doneprotected double calculateSE(boolean[] selectedAttributes,
double[] coefficients)
throws java.lang.Exception
selectedAttributes - an array of flags indicating which attributes are included in the regression modelcoefficients - an array of coefficients for the regression modeljava.lang.Exception - if there is a missing class value in the training dataprotected double regressionPrediction(Instance transformedInstance, boolean[] selectedAttributes, double[] coefficients) throws java.lang.Exception
transformedInstance - the input instanceselectedAttributes - an array of flags indicating which attributes are included in the regression modelcoefficients - an array of coefficients for the regression modeljava.lang.Exception - if the class attribute of the input instance is not assignedprotected double[] doRegression(boolean[] selectedAttributes)
throws java.lang.Exception
selectedAttributes - an array of booleans where each element is true if the corresponding attribute should be
included in the regression.java.lang.Exception - if an error occurred during the regression.public java.lang.String getRevision()
getRevision in interface RevisionHandlergetRevision in class AbstractClassifier