weka.classifiers.trees.m5
Class PreConstructedLinearModel

java.lang.Object
  extended byweka.classifiers.Classifier
      extended byweka.classifiers.trees.m5.PreConstructedLinearModel
All Implemented Interfaces:
java.lang.Cloneable, OptionHandler, java.io.Serializable

public class PreConstructedLinearModel
extends Classifier
implements java.io.Serializable

This class encapsulates a linear regression function. It is a classifier but does not learn the function itself, instead it is constructed with coefficients and intercept obtained elsewhere. The buildClassifier method must still be called however as this stores a copy of the training data's header for use in printing the model to the console.

Version:
$Revision: 1.2 $
Author:
Mark Hall (mhall@cs.waikato.ac.nz)
See Also:
Serialized Form

Field Summary
private  double[] m_coefficients
           
private  Instances m_instancesHeader
           
private  double m_intercept
           
private  int m_numParameters
           
 
Fields inherited from class weka.classifiers.Classifier
m_Debug
 
Constructor Summary
PreConstructedLinearModel(double[] coeffs, double intercept)
          Constructor
 
Method Summary
 void buildClassifier(Instances instances)
          Builds the classifier.
 double classifyInstance(Instance inst)
          Predicts the class of the supplied instance using the linear model.
 double[] coefficients()
          Return the array of coefficients
 double intercept()
          Return the intercept
 int numParameters()
          Return the number of parameters (coefficients) in the linear model
 java.lang.String toString()
          Returns a textual description of this linear model
 
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_coefficients

private double[] m_coefficients

m_intercept

private double m_intercept

m_instancesHeader

private Instances m_instancesHeader

m_numParameters

private int m_numParameters
Constructor Detail

PreConstructedLinearModel

public PreConstructedLinearModel(double[] coeffs,
                                 double intercept)
Constructor

Parameters:
coeffs - an array of coefficients
intercept - the intercept
Method Detail

buildClassifier

public void buildClassifier(Instances instances)
                     throws java.lang.Exception
Builds the classifier. In this case all that is done is that a copy of the training instances header is saved.

Specified by:
buildClassifier in class Classifier
Parameters:
instances - an Instances value
Throws:
java.lang.Exception - if an error occurs

classifyInstance

public double classifyInstance(Instance inst)
                        throws java.lang.Exception
Predicts the class of the supplied instance using the linear model.

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

numParameters

public int numParameters()
Return the number of parameters (coefficients) in the linear model

Returns:
the number of parameters

coefficients

public double[] coefficients()
Return the array of coefficients

Returns:
the coefficients

intercept

public double intercept()
Return the intercept

Returns:
the intercept

toString

public java.lang.String toString()
Returns a textual description of this linear model

Returns:
String containing a description of this linear model