Package edu.cmu.tetrad.classify
Class ClassifierBayesUpdaterDiscrete
java.lang.Object
edu.cmu.tetrad.classify.ClassifierBayesUpdaterDiscrete
- All Implemented Interfaces:
ClassifierDiscrete
,TetradSerializable
,Serializable
public final class ClassifierBayesUpdaterDiscrete
extends Object
implements ClassifierDiscrete, TetradSerializable
This class contains a method classify which uses an instantiated Bayes net (BayesIm) provided in the constructor. For
each case (record) in the DataSet it uses the values of all variables but the target variable to update the
distributions of all the variables. It then computes an estimated value for the target variable by selecting the
value with the greatest probability in the updated distribution. The method returns a crosstabulation table in the
form of a two-dimensional integer array in which coefs of observed versus estimated values of the target variable are
stored. Note that the variables must be the same in the dataset and the Bayes net.
- Version:
- $Id: $Id
- Author:
- Frank Wimberly based on a specification by Clark Glymour
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionClassifierBayesUpdaterDiscrete
(BayesIm bayesIm, DataSet testData) The constructor sets the values of the private member variables. -
Method Summary
Modifier and TypeMethodDescriptionint[]
classify()
Computes and returns the cross-tabulation of observed versus estimated values of the target variable as described above.int[][]
Computes the "confusion matrix" of coefs of the number of cases associated with each combination of estimated and observed values in the test dataset.Returns the Bayes IM being used.Returns the variables of the BayesIM.int[]
Returns the classification for the target variable.double[][]
Returns the marginals.int
Returns the number of cases for the data.double
Getter for the fieldpercentCorrect
.Getter for the fieldtargetVariable
.Returns the test data being used.int
Returns the number of usable cases for the data.Generates a simple exemplar of this class to test serialization.void
Sets the target variable.
-
Constructor Details
-
ClassifierBayesUpdaterDiscrete
The constructor sets the values of the private member variables. The BayesIm instance is used to create an updater. The dataset to be classified is the test data. The variables in the dataset to be classified are the same as the variables in the Bayes net. The target variable is not set.- Parameters:
bayesIm
- the BayesIm instance used to create an updater.testData
- the dataset to be classified.
-
-
Method Details
-
serializableInstance
Generates a simple exemplar of this class to test serialization.- Returns:
- a simple exemplar of this class to test serialization.
-
setTarget
-
classify
public int[] classify()Computes and returns the cross-tabulation of observed versus estimated values of the target variable as described above.- Specified by:
classify
in interfaceClassifierDiscrete
- Returns:
- this cross-tabulation.
-
crossTabulation
public int[][] crossTabulation()Computes the "confusion matrix" of coefs of the number of cases associated with each combination of estimated and observed values in the test dataset. Each row, column i,j corresponds to the ith and jth categories of the target variable.- Specified by:
crossTabulation
in interfaceClassifierDiscrete
- Returns:
- an int[][] array containing the coefs, or null if the target variable is not in the test data.
-
getPercentCorrect
public double getPercentCorrect()Getter for the field
percentCorrect
.- Specified by:
getPercentCorrect
in interfaceClassifierDiscrete
- Returns:
- the percentage of cases in which the target variable is correctly classified.
-
getTargetVariable
Getter for the field
targetVariable
.- Returns:
- the discrete variables which is the target variable.
- See Also:
-
getBayesIm
-
getTestData
-
getClassifications
public int[] getClassifications()Returns the classification for the target variable.- Returns:
- Thsi classification.
-
getMarginals
public double[][] getMarginals()Returns the marginals.- Returns:
- This.
-
getNumCases
public int getNumCases()Returns the number of cases for the data.- Returns:
- This number.
-
getTotalUsableCases
public int getTotalUsableCases()Returns the number of usable cases for the data.- Returns:
- Thsi number.
-
getBayesImVars
-