程序包 weka.classifiers
类 CostMatrix
java.lang.Object
weka.classifiers.CostMatrix
- 所有已实现的接口:
Serializable
,RevisionHandler
Class for storing and manipulating a misclassification cost matrix. The
element at position i,j in the matrix is the penalty for classifying an
instance of class j as class i. Cost values can be fixed or computed on a
per-instance basis (cost sensitive evaluation only) from the value of an
attribute or an expression involving attribute(s).
- 版本:
- $Revision: 9048 $
- 作者:
- Mark Hall, Richard Kirkby (rkirkby@cs.waikato.ac.nz)
- 另请参阅:
-
字段概要
字段 -
构造器概要
构造器构造器说明CostMatrix
(int numOfClasses) Creates a default cost matrix of a particular size.CostMatrix
(Reader reader) Reads a matrix from a reader.CostMatrix
(CostMatrix toCopy) Creates a cost matrix that is a copy of another. -
方法概要
修饰符和类型方法说明applyCostMatrix
(Instances data, Random random) Applies the cost matrix to a set of instances.double[]
expectedCosts
(double[] classProbs) Calculates the expected misclassification cost for each possible class value, given class probability estimates.double[]
expectedCosts
(double[] classProbs, Instance inst) Calculates the expected misclassification cost for each possible class value, given class probability estimates.final Object
getCell
(int rowIndex, int columnIndex) Return the contents of a particular cell.final double
getElement
(int rowIndex, int columnIndex) Return the value of a cell as a double (for legacy code)final double
getElement
(int rowIndex, int columnIndex, Instance inst) Return the value of a cell as a double.double
getMaxCost
(int classVal) Gets the maximum cost for a particular class value.double
getMaxCost
(int classVal, Instance inst) Gets the maximum cost for a particular class value.Returns the revision string.void
Initializes the matrixvoid
Normalizes the matrix so that the diagonal contains zeros.int
Same as sizeint
numRows()
Same as sizestatic CostMatrix
parseMatlab
(String matlab) creates a matrix from the given Matlab string.void
readOldFormat
(Reader reader) Loads a cost matrix in the old format from a reader.final void
Set the value of a particular cell in the matrixfinal void
setElement
(int rowIndex, int columnIndex, double value) Set the value of a cell as a doubleint
size()
The number of rows (and columns)toMatlab()
converts the Matrix into a single line Matlab string: matrix is enclosed by parentheses, rows are separated by semicolon and single cells by blanks, e.g., [1 2; 3 4].toString()
Converts a matrix to a string.void
Writes out a matrix.
-
字段详细资料
-
FILE_EXTENSION
The deafult file extension for cost matrix files
-
-
构造器详细资料
-
CostMatrix
public CostMatrix(int numOfClasses) Creates a default cost matrix of a particular size. All diagonal values will be 0 and all non-diagonal values 1.- 参数:
numOfClasses
- the number of classes that the cost matrix holds.
-
CostMatrix
Creates a cost matrix that is a copy of another.- 参数:
toCopy
- the matrix to copy.
-
CostMatrix
Reads a matrix from a reader. The first line in the file should contain the number of rows and columns. Subsequent lines contain elements of the matrix. (FracPete: taken from old weka.core.Matrix class)- 参数:
reader
- the reader containing the matrix- 抛出:
Exception
- if an error occurs- 另请参阅:
-
-
方法详细资料
-
initialize
public void initialize()Initializes the matrix -
size
public int size()The number of rows (and columns)- 返回:
- the size of the matrix
-
numColumns
public int numColumns()Same as size- 返回:
- the number of columns
-
numRows
public int numRows()Same as size- 返回:
- the number of rows
-
applyCostMatrix
Applies the cost matrix to a set of instances. If a random number generator is supplied the instances will be resampled, otherwise they will be rewighted. Adapted from code once sitting in Instances.java- 参数:
data
- the instances to reweight.random
- a random number generator for resampling, if null then instances are rewighted.- 返回:
- a new dataset reflecting the cost of misclassification.
- 抛出:
Exception
- if the data has no class or the matrix in inappropriate.
-
expectedCosts
Calculates the expected misclassification cost for each possible class value, given class probability estimates.- 参数:
classProbs
- the class probability estimates.- 返回:
- the expected costs.
- 抛出:
Exception
- if the wrong number of class probabilities is supplied.
-
expectedCosts
Calculates the expected misclassification cost for each possible class value, given class probability estimates.- 参数:
classProbs
- the class probability estimates.inst
- the current instance for which the class probabilites apply. Is used for computing any non-fixed cost values.- 返回:
- the expected costs.
- 抛出:
Exception
- if something goes wrong
-
getMaxCost
Gets the maximum cost for a particular class value.- 参数:
classVal
- the class value.- 返回:
- the maximum cost.
- 抛出:
Exception
- if cost matrix contains non-fixed costs
-
getMaxCost
Gets the maximum cost for a particular class value.- 参数:
classVal
- the class value.- 返回:
- the maximum cost.
- 抛出:
Exception
- if cost matrix contains non-fixed costs
-
normalize
public void normalize()Normalizes the matrix so that the diagonal contains zeros. -
readOldFormat
Loads a cost matrix in the old format from a reader. Adapted from code once sitting in Instances.java- 参数:
reader
- the reader to get the values from.- 抛出:
Exception
- if the matrix cannot be read correctly.
-
write
Writes out a matrix. The format can be read via the CostMatrix(Reader) constructor. (FracPete: taken from old weka.core.Matrix class)- 参数:
w
- the output Writer- 抛出:
Exception
- if an error occurs
-
toMatlab
converts the Matrix into a single line Matlab string: matrix is enclosed by parentheses, rows are separated by semicolon and single cells by blanks, e.g., [1 2; 3 4].- 返回:
- the matrix in Matlab single line format
-
setCell
Set the value of a particular cell in the matrix- 参数:
rowIndex
- the rowcolumnIndex
- the columnvalue
- the value to set
-
getCell
Return the contents of a particular cell. Note: this method returns the Object stored at a particular cell.- 参数:
rowIndex
- the rowcolumnIndex
- the column- 返回:
- the value at the cell
-
getElement
Return the value of a cell as a double (for legacy code)- 参数:
rowIndex
- the rowcolumnIndex
- the column- 返回:
- the value at a particular cell as a double
- 抛出:
Exception
- if the value is not a double
-
getElement
Return the value of a cell as a double. Computes the value for non-fixed costs using the supplied Instance- 参数:
rowIndex
- the rowcolumnIndex
- the column- 返回:
- the value from a particular cell
- 抛出:
Exception
- if something goes wrong
-
setElement
public final void setElement(int rowIndex, int columnIndex, double value) Set the value of a cell as a double- 参数:
rowIndex
- the rowcolumnIndex
- the columnvalue
- the value (double) to set
-
parseMatlab
creates a matrix from the given Matlab string.- 参数:
matlab
- the matrix in matlab format- 返回:
- the matrix represented by the given string
- 抛出:
Exception
- 另请参阅:
-
toString
Converts a matrix to a string. (FracPete: taken from old weka.core.Matrix class) -
getRevision
Returns the revision string.- 指定者:
getRevision
在接口中RevisionHandler
- 返回:
- the revision
-