|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectweka.classifiers.CostMatrix
public class CostMatrix
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).
| Field Summary | |
|---|---|
static java.lang.String |
FILE_EXTENSION
The deafult file extension for cost matrix files |
| Constructor Summary | |
|---|---|
CostMatrix(CostMatrix toCopy)
Creates a cost matrix that is a copy of another. |
|
CostMatrix(int numOfClasses)
Creates a default cost matrix of a particular size. |
|
CostMatrix(java.io.Reader reader)
Reads a matrix from a reader. |
|
| Method Summary | |
|---|---|
Instances |
applyCostMatrix(Instances data,
java.util.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. |
java.lang.Object |
getCell(int rowIndex,
int columnIndex)
Return the contents of a particular cell. |
double |
getElement(int rowIndex,
int columnIndex)
Return the value of a cell as a double (for legacy code) |
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. |
java.lang.String |
getRevision()
Returns the revision string. |
void |
initialize()
Initializes the matrix |
void |
normalize()
Normalizes the matrix so that the diagonal contains zeros. |
int |
numColumns()
Same as size |
int |
numRows()
Same as size |
static Matrix |
parseMatlab(java.lang.String matlab)
creates a matrix from the given Matlab string. |
void |
readOldFormat(java.io.Reader reader)
Loads a cost matrix in the old format from a reader. |
void |
setCell(int rowIndex,
int columnIndex,
java.lang.Object value)
Set the value of a particular cell in the matrix |
void |
setElement(int rowIndex,
int columnIndex,
double value)
Set the value of a cell as a double |
int |
size()
The number of rows (and columns) |
java.lang.String |
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]. |
java.lang.String |
toString()
Converts a matrix to a string. |
void |
write(java.io.Writer w)
Writes out a matrix. |
| Methods inherited from class java.lang.Object |
|---|
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
public static java.lang.String FILE_EXTENSION
| Constructor Detail |
|---|
public CostMatrix(int numOfClasses)
numOfClasses - the number of classes that the cost matrix holds.public CostMatrix(CostMatrix toCopy)
toCopy - the matrix to copy.
public CostMatrix(java.io.Reader reader)
throws java.lang.Exception
reader - the reader containing the matrix
java.lang.Exception - if an error occurswrite(Writer)| Method Detail |
|---|
public void initialize()
public int size()
public int numColumns()
public int numRows()
public Instances applyCostMatrix(Instances data,
java.util.Random random)
throws java.lang.Exception
data - the instances to reweight.random - a random number generator for resampling, if null then instances are
rewighted.
java.lang.Exception - if the data has no class or the matrix in inappropriate.
public double[] expectedCosts(double[] classProbs)
throws java.lang.Exception
classProbs - the class probability estimates.
java.lang.Exception - if the wrong number of class probabilities is supplied.
public double[] expectedCosts(double[] classProbs,
Instance inst)
throws java.lang.Exception
classProbs - the class probability estimates.inst - the current instance for which the class probabilites
apply. Is used for computing any non-fixed cost values.
java.lang.Exception - if something goes wrong
public double getMaxCost(int classVal)
throws java.lang.Exception
classVal - the class value.
java.lang.Exception - if cost matrix contains non-fixed
costs
public double getMaxCost(int classVal,
Instance inst)
throws java.lang.Exception
classVal - the class value.
java.lang.Exception - if cost matrix contains non-fixed
costspublic void normalize()
public void readOldFormat(java.io.Reader reader)
throws java.lang.Exception
reader - the reader to get the values from.
java.lang.Exception - if the matrix cannot be read correctly.
public void write(java.io.Writer w)
throws java.lang.Exception
w - the output Writer
java.lang.Exception - if an error occurspublic java.lang.String toMatlab()
public final void setCell(int rowIndex,
int columnIndex,
java.lang.Object value)
rowIndex - the rowcolumnIndex - the columnvalue - the value to set
public final java.lang.Object getCell(int rowIndex,
int columnIndex)
rowIndex - the rowcolumnIndex - the column
public final double getElement(int rowIndex,
int columnIndex)
throws java.lang.Exception
rowIndex - the rowcolumnIndex - the column
java.lang.Exception - if the value is not a double
public final double getElement(int rowIndex,
int columnIndex,
Instance inst)
throws java.lang.Exception
rowIndex - the rowcolumnIndex - the column
java.lang.Exception - if something goes wrong
public final void setElement(int rowIndex,
int columnIndex,
double value)
rowIndex - the rowcolumnIndex - the columnvalue - the value (double) to set
public static Matrix parseMatlab(java.lang.String matlab)
throws java.lang.Exception
matlab - the matrix in matlab format
java.lang.Exceptionpublic java.lang.String toString()
toString in class java.lang.Objectpublic java.lang.String getRevision()
getRevision in interface RevisionHandler
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||