jsat.classifiers.bayesian
Class ConditionalProbabilityTable
- java.lang.Object
-
- jsat.classifiers.bayesian.ConditionalProbabilityTable
-
- All Implemented Interfaces:
- java.io.Serializable, java.lang.Cloneable, Classifier
public class ConditionalProbabilityTable extends java.lang.Object implements Classifier
The conditional probability table (CPT) is a classifier for categorical attributes. It builds the whole conditional probability table for a data set. The size of the CPT grows exponentially with the number of dimensions and options, and requires exponentially more data to get a good fit. CPTs can be useful for small data sets, or as a building block for another algorithm- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor and Description ConditionalProbabilityTable()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description CategoricalResultsclassify(DataPoint data)Performs classification on the given data point.Classifierclone()intdataPointToCord(DataPointPair<java.lang.Integer> dataPoint, int targetClass, int[] cord)Converts a data point pair into a coordinate.intgetDimensionSize()Returns the number of dimensions in the CPTdoublequery(int targetClass, DataPointPair<java.lang.Integer> dataPoint)Queries the CPT for the probability that the class value of targetClas would occur with the given DataPointPair.doublequery(int targetClass, int targetValue, int[] cord)Queries the CPT for the probability of the target class occurring with the specified value given the class values of the other attributesbooleansupportsWeightedData()Indicates whether the model knows how to train using weighted data points.voidtrain(ClassificationDataSet dataSet)Trains the classifier and constructs a model for classification using the given data set.voidtrain(ClassificationDataSet dataSet, boolean parallel)Trains the classifier and constructs a model for classification using the given data set.voidtrainC(ClassificationDataSet dataSet, java.util.Set<java.lang.Integer> categoriesToUse)Creates a CPT using only a subset of the features specified by categoriesToUse.
-
-
-
Method Detail
-
classify
public CategoricalResults classify(DataPoint data)
Description copied from interface:ClassifierPerforms classification on the given data point.- Specified by:
classifyin interfaceClassifier- Parameters:
data- the data point to classify- Returns:
- the results of the classification.
-
getDimensionSize
public int getDimensionSize()
Returns the number of dimensions in the CPT- Returns:
- the number of dimensions in the CPT
-
dataPointToCord
public int dataPointToCord(DataPointPair<java.lang.Integer> dataPoint, int targetClass, int[] cord)
Converts a data point pair into a coordinate. The paired value contains the value for the predicting index. Though this value will not be used if the predicting class of the original data set was not used to make the table.- Parameters:
dataPoint- the DataPointPair to converttargetClass- the index in the original data set of the category that we would like to predictcord- the array to store the coordinate in.- Returns:
- the value of the target class for the given data point
- Throws:
java.lang.ArithmeticException- if the cord array does not match thedimensionof the CPT
-
train
public void train(ClassificationDataSet dataSet, boolean parallel)
Description copied from interface:ClassifierTrains the classifier and constructs a model for classification using the given data set. If the training method knows how, it will used the threadPool to conduct training in parallel. This method will block until the training has completed.- Specified by:
trainin interfaceClassifier- Parameters:
dataSet- the data set to train onparallel-trueif multiple threads should be used to train the model.falseif it should be done in a single threaded manner.
-
train
public void train(ClassificationDataSet dataSet)
Description copied from interface:ClassifierTrains the classifier and constructs a model for classification using the given data set.- Specified by:
trainin interfaceClassifier- Parameters:
dataSet- the data set to train on
-
trainC
public void trainC(ClassificationDataSet dataSet, java.util.Set<java.lang.Integer> categoriesToUse)
Creates a CPT using only a subset of the features specified by categoriesToUse.- Parameters:
dataSet- the data set to train fromcategoriesToUse- the attributes to use in training. Each value corresponds to the categorical index in dataSet, and adding the valueDataSet.getNumCategoricalVars(), which is not a valid index, indicates to used thepredicting classof the data set in the CPT.
-
query
public double query(int targetClass, DataPointPair<java.lang.Integer> dataPoint)Queries the CPT for the probability that the class value of targetClas would occur with the given DataPointPair.- Parameters:
targetClass- the index in the original data set of the class that we want the probability ofdataPoint- the data point of values paired with the value of the predicting attribute in the original training set- Returns:
- the probability in [0,1] of the target class value occurring with the given DataPointPair
-
query
public double query(int targetClass, int targetValue, int[] cord)Queries the CPT for the probability of the target class occurring with the specified value given the class values of the other attributes- Parameters:
targetClass- the index in the original data set of the class that we want to probability oftargetValue- the value of the targetClass that we want to probability of occurringcord- the coordinate array that corresponds the the class values for the CPT, where the coordinate of the targetClass may contain any value.- Returns:
- the probability in [0, 1] of the targetClass occurring with the targetValue given the information in cord
- See Also:
dataPointToCord(jsat.classifiers.DataPointPair, int, int[])
-
supportsWeightedData
public boolean supportsWeightedData()
Description copied from interface:ClassifierIndicates whether the model knows how to train using weighted data points. If it does, the model will train assuming the weights. The values returned by this method may change depending on the parameters set for the model.- Specified by:
supportsWeightedDatain interfaceClassifier- Returns:
- true if the model supports weighted data, false otherwise
-
clone
public Classifier clone()
- Specified by:
clonein interfaceClassifier- Overrides:
clonein classjava.lang.Object
-
-
DataMelt 3.0 © DataMelt by jWork.ORG