Package weka.classifiers.trees.m5

# Class PreConstructedLinearModel

java.lang.Object
weka.classifiers.AbstractClassifier
weka.classifiers.trees.m5.PreConstructedLinearModel

All Implemented Interfaces:
  `Serializable`, `Cloneable`, `Classifier`, `BatchPredictor`, `CapabilitiesHandler`, `CapabilitiesIgnorer`, `CommandlineRunnable`, `OptionHandler`, `RevisionHandler`

public class PreConstructedLinearModel extends AbstractClassifier implements 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: 15358 $
Author:
  Mark Hall (mhall@cs.waikato.ac.nz)
See Also:
  - Serialized Form

- ## Field Summary

  ### Fields inherited from class weka.classifiers.AbstractClassifier

  `BATCH_SIZE_DEFAULT, NUM_DECIMAL_PLACES_DEFAULT`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `PreConstructedLinearModel(double[] coeffs, double intercept)`
  Constructor

- ## Method Summary

  Modifier and Type
  Method
  Description
  `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
  `String`
  `getRevision()`
  Returns the revision string.
  `double`
  `intercept()`
  Return the intercept
  `int`
  `numParameters()`
  Return the number of parameters (coefficients) in the linear model
  `String`
  `toString()`
  Returns a textual description of this linear model

  ### Methods inherited from class weka.classifiers.AbstractClassifier

  `batchSizeTipText, debugTipText, distributionForInstance, distributionsForInstances, doNotCheckCapabilitiesTipText, forName, getBatchSize, getCapabilities, getDebug, getDoNotCheckCapabilities, getNumDecimalPlaces, getOptions, implementsMoreEfficientBatchPrediction, listOptions, makeCopies, makeCopy, numDecimalPlacesTipText, postExecution, preExecution, run, runClassifier, setBatchSize, setDebug, setDoNotCheckCapabilities, setNumDecimalPlaces, setOptions`

  ### Methods inherited from class java.lang.Object

  `equals, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- ## Constructor Details

  - ### PreConstructedLinearModel

    public PreConstructedLinearModel(double[] coeffs, double intercept)
    Constructor
    Parameters:
      `coeffs` - an array of coefficients
      `intercept` - the intercept

- ## Method Details

  - ### buildClassifier

    public void buildClassifier(Instances instances) throws 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 interface `Classifier`
    Parameters:
      `instances` - an `Instances` value
    Throws:
      `Exception` - if an error occurs

  - ### classifyInstance

    public double classifyInstance(Instance inst) throws Exception
    Predicts the class of the supplied instance using the linear model.
    Specified by:
      `classifyInstance` in interface `Classifier`
    Overrides:
      `classifyInstance` in class `AbstractClassifier`
    Parameters:
      `inst` - the instance to make a prediction for
    Returns:
      the prediction
    Throws:
      `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 String toString()
    Returns a textual description of this linear model
    Overrides:
      `toString` in class `Object`
    Returns:
      String containing a description of this linear model

  - ### getRevision

    public String getRevision()
    Returns the revision string.
    Specified by:
      `getRevision` in interface `RevisionHandler`
    Overrides:
      `getRevision` in class `AbstractClassifier`
    Returns:
      the revision