org.knime.base.node.mine.bayes.naivebayes.predictor
Class NaiveBayesCellFactory

java.lang.Object
  extended by org.knime.base.node.mine.bayes.naivebayes.predictor.NaiveBayesCellFactory
All Implemented Interfaces:
AppendedCellFactory, CellFactory

public class NaiveBayesCellFactory
extends Object
implements AppendedCellFactory, CellFactory

Naive Bayes AppendCellFactory class which uses the given NaiveBayesModel to predict the class membership of each row.

Author:
Tobias Koetter, University of Konstanz

Constructor Summary
NaiveBayesCellFactory(NaiveBayesModel model, DataTableSpec tableSpec, boolean inclClassProbVals)
          Constructor for class NaiveBayesAlgorithm.
NaiveBayesCellFactory(NaiveBayesModel model, DataTableSpec tableSpec, boolean inclClassProbVals, double laplaceCorrector)
          Constructor for class NaiveBayesAlgorithm.
 
Method Summary
static DataColumnSpec createResultColSpecs(DataColumnSpec classColumn, DataTableSpec inSpec, boolean inclClassProbVals)
          Creates the column specification of the result columns and returns them in the order they should be appended to the original table specification.
static DataColumnSpec[] createResultColSpecs(NaiveBayesModel model, DataTableSpec inSpec, boolean inclClassProbVals)
          Creates the column specification of the result columns and returns them in the order they should be appended to the original table specification.
 DataCell[] getAppendedCell(DataRow row)
          Get the new cells for a given row.
 DataCell[] getCells(DataRow row)
          Get the new cells for a given row.
 DataColumnSpec[] getColumnSpecs()
          The column specs for the cells that are generated in the getCells() method.
 DataColumnSpec[] getResultColumnsSpec()
           
 void setProgress(int curRowNr, int rowCount, RowKey lastKey, ExecutionMonitor exec)
          This method is called when a row has been processed.
 String toString()
          
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

NaiveBayesCellFactory

public NaiveBayesCellFactory(NaiveBayesModel model,
                             DataTableSpec tableSpec,
                             boolean inclClassProbVals)
Constructor for class NaiveBayesAlgorithm.

Parameters:
model - the NaiveBayesModel which holds all necessary information to calculate the probability for new records.
tableSpec - the basic table specification
inclClassProbVals - if the probability per class instance should be appended as columns

NaiveBayesCellFactory

public NaiveBayesCellFactory(NaiveBayesModel model,
                             DataTableSpec tableSpec,
                             boolean inclClassProbVals,
                             double laplaceCorrector)
Constructor for class NaiveBayesAlgorithm.

Parameters:
model - the NaiveBayesModel which holds all necessary information to calculate the probability for new records.
tableSpec - the basic table specification
inclClassProbVals - if the probability per class instance should be appended as columns
laplaceCorrector - the Laplace corrector to use. A value greater 0 overcomes zero counts
Method Detail

createResultColSpecs

public static DataColumnSpec[] createResultColSpecs(NaiveBayesModel model,
                                                    DataTableSpec inSpec,
                                                    boolean inclClassProbVals)
Creates the column specification of the result columns and returns them in the order they should be appended to the original table specification.

Parameters:
model - the NaiveBayesModel to use
inSpec - the DataTableSpec of the input data to check if the winner column name already exists
inclClassProbVals - if the probability values should be displayed
Returns:
DataColumnSpec[] with the column specifications of the result columns

createResultColSpecs

public static DataColumnSpec createResultColSpecs(DataColumnSpec classColumn,
                                                  DataTableSpec inSpec,
                                                  boolean inclClassProbVals)
Creates the column specification of the result columns and returns them in the order they should be appended to the original table specification.

Parameters:
classColumn - the class column spec
inSpec - the DataTableSpec of the input data to check if the winner column name already exists
inclClassProbVals - if the probability values should be displayed
Returns:
DataColumnSpec[] with the column specifications of the result columns

getResultColumnsSpec

public DataColumnSpec[] getResultColumnsSpec()
Returns:
the specification of the result columns in the order they should be append at the end of the original table specification

getAppendedCell

public DataCell[] getAppendedCell(DataRow row)
Get the new cells for a given row. These cells are appended to the existing row.

Specified by:
getAppendedCell in interface AppendedCellFactory
Parameters:
row - The row of interest.
Returns:
The appended cells to that row.

toString

public String toString()

Overrides:
toString in class Object

getCells

public DataCell[] getCells(DataRow row)
Get the new cells for a given row. These cells are incorporated into the existing row. The way it is done is defined through the ColumnRearranger using this object.

Specified by:
getCells in interface CellFactory
Parameters:
row - The row of interest.
Returns:
The new cells to that row.

getColumnSpecs

public DataColumnSpec[] getColumnSpecs()
The column specs for the cells that are generated in the getCells() method. This method is only called once, there is no need to cache the return value. The length of the returned array must match the length of the array returned by the getCells(DataRow) method and also the types must match, i.e. the type of the respective DataColumnSpec must be of the same type or a super type of the cell as returned by getCells(DataRow).

Specified by:
getColumnSpecs in interface CellFactory
Returns:
The specs to the newly created cells.

setProgress

public void setProgress(int curRowNr,
                        int rowCount,
                        RowKey lastKey,
                        ExecutionMonitor exec)
This method is called when a row has been processed. It allows the implementor to set progress in the execution monitor and also some meaningful progress message.

Note, you don't need to check exec.checkCanceled() in the implementation as this is done in the calling class.

Specified by:
setProgress in interface CellFactory
Parameters:
curRowNr - The number of the row just processed
rowCount - The total number of rows.
lastKey - The row's key.
exec - The execution monitor to report progress to.


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.