|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectweka.classifiers.Classifier
weka.classifiers.functions.LinearRegression
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.
-S num
Set the attriute selection method to use. 1 = None, 2 = Greedy
(default 0 = M5' method)
-C
Do not try to eliminate colinear attributes
-R num
The ridge parameter (default 1.0e-8)
Field Summary | |
private boolean |
b_Debug
True if debug output will be printed |
private int |
m_AttributeSelection
The current attribute selection method |
private boolean |
m_checksTurnedOff
Turn off all checks and conversions? |
private int |
m_ClassIndex
The index of the class attribute |
private double |
m_ClassMean
The mean of the class attribute |
private double |
m_ClassStdDev
The standard deviations of the class attribute |
private double[] |
m_Coefficients
Array for storing coefficients of linear regression. |
private boolean |
m_EliminateColinearAttributes
Try to eliminate correlated attributes? |
private double[] |
m_Means
The attributes means |
private ReplaceMissingValues |
m_MissingFilter
The filter for removing missing values. |
private double |
m_Ridge
The ridge parameter |
private boolean[] |
m_SelectedAttributes
Which attributes are relevant? |
private double[] |
m_StdDevs
The attribute standard deviations |
private Instances |
m_TransformedData
Variable for storing transformed training data. |
private NominalToBinary |
m_TransformFilter
The filter storing the transformation from nominal to binary attributes. |
static int |
SELECTION_GREEDY
|
static int |
SELECTION_M5
|
static int |
SELECTION_NONE
|
static Tag[] |
TAGS_SELECTION
|
Fields inherited from class weka.classifiers.Classifier |
m_Debug |
Constructor Summary | |
LinearRegression()
|
Method Summary | |
java.lang.String |
attributeSelectionMethodTipText()
Returns the tip text for this property |
void |
buildClassifier(Instances data)
Builds a regression model for the given data. |
private 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. |
java.lang.String |
debugTipText()
Returns the tip text for this property |
private boolean |
deselectColinearAttributes(boolean[] selectedAttributes,
double[] coefficients)
Removes the attribute with the highest standardised coefficient greater than 1.5 from the selected attributes. |
private double[] |
doRegression(boolean[] selectedAttributes)
Calculate a linear regression using the selected attributes |
java.lang.String |
eliminateColinearAttributesTipText()
Returns the tip text for this property |
private 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. |
boolean |
getDebug()
Controls whether debugging output will be printed |
boolean |
getEliminateColinearAttributes()
Get the value of EliminateColinearAttributes. |
java.lang.String[] |
getOptions()
Gets the current settings of the classifier. |
double |
getRidge()
Get the value of Ridge. |
java.lang.String |
globalInfo()
Returns a string describing this classifier |
java.util.Enumeration |
listOptions()
Returns an enumeration describing the available options. |
static void |
main(java.lang.String[] argv)
Generates a linear regression function predictor. |
int |
numParameters()
Get the number of coefficients used in the model |
private 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 |
setDebug(boolean debug)
Controls whether debugging output will be printed |
void |
setEliminateColinearAttributes(boolean newEliminateColinearAttributes)
Set the value of EliminateColinearAttributes. |
void |
setOptions(java.lang.String[] options)
Parses a given list of options. |
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. |
Methods inherited from class weka.classifiers.Classifier |
distributionForInstance, forName, makeCopies |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
private double[] m_Coefficients
private boolean[] m_SelectedAttributes
private Instances m_TransformedData
private ReplaceMissingValues m_MissingFilter
private NominalToBinary m_TransformFilter
private double m_ClassStdDev
private double m_ClassMean
private int m_ClassIndex
private double[] m_Means
private double[] m_StdDevs
private boolean b_Debug
private int m_AttributeSelection
public static final int SELECTION_M5
public static final int SELECTION_NONE
public static final int SELECTION_GREEDY
public static final Tag[] TAGS_SELECTION
private boolean m_EliminateColinearAttributes
private boolean m_checksTurnedOff
private double m_Ridge
Constructor Detail |
public LinearRegression()
Method Detail |
public void turnChecksOff()
public void turnChecksOn()
public java.lang.String globalInfo()
public void buildClassifier(Instances data) throws java.lang.Exception
buildClassifier
in class Classifier
data
- the training data to be used for generating the
linear regression function
java.lang.Exception
- if the classifier could not be built successfullypublic double classifyInstance(Instance instance) throws java.lang.Exception
classifyInstance
in class Classifier
instance
- the test instance
java.lang.Exception
- if classification can't be done successfullypublic java.lang.String toString()
public java.util.Enumeration listOptions()
listOptions
in interface OptionHandler
listOptions
in class Classifier
public void setOptions(java.lang.String[] options) throws java.lang.Exception
-D
Produce debugging output.
-S num
Set the attriute selection method to use. 1 = None, 2 = Greedy
(default 0 = M5' method)
-C
Do not try to eliminate colinear attributes
-R num
The ridge parameter (default 1.0e-8)
setOptions
in interface OptionHandler
setOptions
in class Classifier
options
- the list of options as an array of strings
java.lang.Exception
- if an option is not supportedpublic double[] coefficients()
public java.lang.String[] getOptions()
getOptions
in interface OptionHandler
getOptions
in class Classifier
public 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 void setAttributeSelectionMethod(SelectedTag method)
method
- the attribute selection method to use.public SelectedTag getAttributeSelectionMethod()
public java.lang.String debugTipText()
debugTipText
in class Classifier
public void setDebug(boolean debug)
setDebug
in class Classifier
debug
- true if debugging output should be printedpublic boolean getDebug()
getDebug
in class Classifier
private 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
model
private void findBestModel() throws java.lang.Exception
java.lang.Exception
- if regression can't be doneprivate 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
model
java.lang.Exception
- if there is a missing class value in the training
dataprivate 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
model
java.lang.Exception
- if the class attribute of the input instance
is not assignedprivate 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 static void main(java.lang.String[] argv)
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |