org.knime.base.node.mine.regression.linear
Class LinearRegressionContent

java.lang.Object
  extended by org.knime.base.node.mine.regression.linear.LinearRegressionContent

public final class LinearRegressionContent
extends Object

Utility class that carries out the loading and saving of linear regression models. It is used by the learner node model and the predictor node model.

Author:
Bernd Wiswedel, University of Konstanz

Constructor Summary
LinearRegressionContent()
          Public no arg constructor as required by super class.
LinearRegressionContent(DataTableSpec spec, double offset, double[] multipliers, double[] means)
          Create new object with the given parameters.
 
Method Summary
 PMMLRegressionPortObject createPortObject()
          Creates a new PMML regression port object from this linear regression model.
static PMMLPortObjectSpec createPortObjectSpec(DataTableSpec spec)
          Creates a PMML port object spec based on all columns in the given data table spec.
 double getApproximationFor(String variable, double v)
          Does a prediction when the given variable has the value v and all other variables have their mean value.
 double[] getMultipliers()
           
 double getOffset()
           
 DataTableSpec getSpec()
           
 String getTargetColumnName()
          Get the name of the response column, i.e.
static LinearRegressionContent instantiateAndLoad(ModelContentRO par, PortObjectSpec spec)
          Creates a new linear regression model that is read from the given model content object.
protected  void load(ModelContentRO par, PortObjectSpec spec)
          Loads a linear regression model from the given model content object.
 DataCell predict(DataRow row)
          Predicts the target value for the given row.
 void save(ModelContentWO par)
          Saves the regression model into the model content object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LinearRegressionContent

public LinearRegressionContent()
Public no arg constructor as required by super class.


LinearRegressionContent

public LinearRegressionContent(DataTableSpec spec,
                               double offset,
                               double[] multipliers,
                               double[] means)
Create new object with the given parameters.

Parameters:
spec - The table spec of the variables
offset - The fixed (constant) offset
multipliers - multiplier values
means - means of all variables (used for 2D plot approximation)
Method Detail

createPortObject

public PMMLRegressionPortObject createPortObject()
                                          throws InvalidSettingsException
Creates a new PMML regression port object from this linear regression model.

Returns:
a port object
Throws:
InvalidSettingsException - if the settings are invalid

createPortObjectSpec

public static PMMLPortObjectSpec createPortObjectSpec(DataTableSpec spec)
                                               throws InvalidSettingsException
Creates a PMML port object spec based on all columns in the given data table spec. The target column must be the last column in the table spec!

Parameters:
spec - the data table spec with which the regression model was created.
Returns:
a PMML port object spec
Throws:
InvalidSettingsException - if PMML incompatible type was found

getTargetColumnName

public String getTargetColumnName()
Get the name of the response column, i.e. the prediction column.

Returns:
the name of the response column

getOffset

public double getOffset()
Returns:
the offset

getMultipliers

public double[] getMultipliers()
Returns:
the multipliers

getApproximationFor

public double getApproximationFor(String variable,
                                  double v)
Does a prediction when the given variable has the value v and all other variables have their mean value. Used to determine the line in a 2D plot.

Parameters:
variable - the variable currently shown on x
v - its value
Returns:
the value of the linear regression line

getSpec

public DataTableSpec getSpec()
Returns:
the spec

predict

public DataCell predict(DataRow row)
Predicts the target value for the given row.

Parameters:
row - a data row to predict
Returns:
the predicted value in a data cell

save

public void save(ModelContentWO par)
Saves the regression model into the model content object.

Parameters:
par - a model content object where the settings are saved to

load

protected void load(ModelContentRO par,
                    PortObjectSpec spec)
             throws InvalidSettingsException
Loads a linear regression model from the given model content object.

Parameters:
par - a model content object
spec - the port object spec
Throws:
InvalidSettingsException - if the model to load in invalid

instantiateAndLoad

public static LinearRegressionContent instantiateAndLoad(ModelContentRO par,
                                                         PortObjectSpec spec)
                                                  throws InvalidSettingsException
Creates a new linear regression model that is read from the given model content object.

Parameters:
par - a model content object
spec - the spec for the model
Returns:
a linear regression model
Throws:
InvalidSettingsException - if the model to load in invalid


Copyright, 2003 - 2010. All rights reserved.
University of Konstanz, Germany.
Chair for Bioinformatics and Information Mining, Prof. Dr. Michael R. Berthold.
You may not modify, publish, transmit, transfer or sell, reproduce, create derivative works from, distribute, perform, display, or in any way exploit any of the content, in whole or in part, except as otherwise expressly permitted in writing by the copyright owner or as specified in the license file distributed with this product.