weka.classifiers.functions
Class SimpleLinearRegression

java.lang.Object
  extended byweka.classifiers.Classifier
      extended byweka.classifiers.functions.SimpleLinearRegression
All Implemented Interfaces:
java.lang.Cloneable, OptionHandler, java.io.Serializable, WeightedInstancesHandler

public class SimpleLinearRegression
extends Classifier
implements WeightedInstancesHandler

Class for learning a simple linear regression model. Picks the attribute that results in the lowest squared error. Missing values are not allowed. Can only deal with numeric attributes.

Version:
$Revision: 1.5 $
Author:
Eibe Frank (eibe@cs.waikato.ac.nz)
See Also:
Serialized Form

Field Summary
private  Attribute m_attribute
          The chosen attribute
private  int m_attributeIndex
          The index of the chosen attribute
private  double m_intercept
          The intercept
private  double m_slope
          The slope
private  boolean m_suppressErrorMessage
          If true, suppress error message if no useful attribute was found
 
Fields inherited from class weka.classifiers.Classifier
m_Debug
 
Constructor Summary
SimpleLinearRegression()
           
 
Method Summary
 void buildClassifier(Instances insts)
          Builds a simple linear regression model given the supplied training data.
 double classifyInstance(Instance inst)
          Generate a prediction for the supplied instance.
 boolean foundUsefulAttribute()
          Returns true if a usable attribute was found.
 int getAttributeIndex()
          Returns the index of the attribute used in the regression.
 double getIntercept()
          Returns the intercept of the function.
 double getSlope()
          Returns the slope of the function.
 java.lang.String globalInfo()
          Returns a string describing this classifier
static void main(java.lang.String[] argv)
          Main method for testing this class
 void setSuppressErrorMessage(boolean s)
          Turn off the error message that is reported when no useful attribute is found.
 java.lang.String toString()
          Returns a description of this classifier as a string
 
Methods inherited from class weka.classifiers.Classifier
debugTipText, distributionForInstance, forName, getDebug, getOptions, listOptions, makeCopies, setDebug, setOptions
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

m_attribute

private Attribute m_attribute
The chosen attribute


m_attributeIndex

private int m_attributeIndex
The index of the chosen attribute


m_slope

private double m_slope
The slope


m_intercept

private double m_intercept
The intercept


m_suppressErrorMessage

private boolean m_suppressErrorMessage
If true, suppress error message if no useful attribute was found

Constructor Detail

SimpleLinearRegression

public SimpleLinearRegression()
Method Detail

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

classifyInstance

public double classifyInstance(Instance inst)
                        throws java.lang.Exception
Generate a prediction for the supplied instance.

Overrides:
classifyInstance in class Classifier
Parameters:
inst - the instance to predict.
Returns:
the prediction
Throws:
java.lang.Exception - if an error occurs

buildClassifier

public void buildClassifier(Instances insts)
                     throws java.lang.Exception
Builds a simple linear regression model given the supplied training data.

Specified by:
buildClassifier in class Classifier
Parameters:
insts - the training data.
Throws:
java.lang.Exception - if an error occurs

foundUsefulAttribute

public boolean foundUsefulAttribute()
Returns true if a usable attribute was found.

Returns:
true if a usable attribute was found.

getAttributeIndex

public int getAttributeIndex()
Returns the index of the attribute used in the regression.

Returns:
the index of the attribute.

getSlope

public double getSlope()
Returns the slope of the function.

Returns:
the slope.

getIntercept

public double getIntercept()
Returns the intercept of the function.

Returns:
the intercept.

setSuppressErrorMessage

public void setSuppressErrorMessage(boolean s)
Turn off the error message that is reported when no useful attribute is found.

Parameters:
s - if set to true turns off the error message

toString

public java.lang.String toString()
Returns a description of this classifier as a string

Returns:
a description of the classifier.

main

public static void main(java.lang.String[] argv)
Main method for testing this class

Parameters:
argv - options