Class NaiveBayesClassifier<U>
java.lang.Object
es.uam.eps.ir.relison.links.linkprediction.supervised.classifiers.NaiveBayesClassifier<U>
- All Implemented Interfaces:
Classifier<U>
public class NaiveBayesClassifier<U> extends java.lang.Object implements Classifier<U>
Classifier which applies the Naive Bayes method. In case the attributes are continuous,
Gaussian Naive Bayes is applied to compute the scores.
Note: For computing the means and variances, an incremental algorithm is used. This algorithm
is documented in:
-
Field Summary
Fields Modifier and Type Field Description private java.util.List<java.lang.String>
attributes
List of attributes.private java.util.List<java.lang.Integer>
classes
List of classes.private java.util.List<java.lang.Double[][]>
frequencies
A list of matrices which contains the information for each attribute in the training set.private static int
MEAN
Constant index for the mean.private boolean
normalize
Indicates if attributes have to be normalized or not.private static int
NUMCONT
Number of parameters in .private int
numInstances
The number of patterns.private java.util.List<java.lang.Double>
priori
Times each class appears in the training set.private static int
SIGMA
Constant index for the variance.private java.util.List<es.uam.eps.ir.ranksys.core.util.Stats>
stats
The stats for each attribute.private boolean
trained
Indicates if the training of the classifier has been done.private java.util.List<FeatureType>
types
The types for each attribute. -
Constructor Summary
Constructors Constructor Description NaiveBayesClassifier()
Constructor.NaiveBayesClassifier(boolean normalize)
Constructor -
Method Summary
Modifier and Type Method Description int
classify(Instance<U> instance)
Obtains the most likely class for a certain instance.double
computeScore(Instance<U> instance, int category)
Gets the score for an individual pattern in a certain category.java.util.Map<java.lang.Integer,java.lang.Double>
computeScores(Instance<U> instance)
Computes the scores for an individual instance (once the training has been done).void
train(InstanceSet<U> trainSet)
Trains the classifier.
-
Field Details
-
trained
private boolean trainedIndicates if the training of the classifier has been done. -
priori
private java.util.List<java.lang.Double> prioriTimes each class appears in the training set. -
frequencies
private java.util.List<java.lang.Double[][]> frequenciesA list of matrices which contains the information for each attribute in the training set. For each matrix, the columns represent the different classes. In the case of nominal attributes, each row represents a different value of the attributes, and each cell contains the number of different examples which share the same value of the attribute and class. In the case of continuous attributes, first row represents the mean of the sample, and second row represents the variance of the sample. -
classes
private java.util.List<java.lang.Integer> classesList of classes. -
attributes
private java.util.List<java.lang.String> attributesList of attributes. -
MEAN
private static final int MEANConstant index for the mean.- See Also:
- Constant Field Values
-
SIGMA
private static final int SIGMAConstant index for the variance.- See Also:
- Constant Field Values
-
NUMCONT
private static final int NUMCONTNumber of parameters in .- See Also:
- Constant Field Values
-
numInstances
private int numInstancesThe number of patterns. -
stats
private java.util.List<es.uam.eps.ir.ranksys.core.util.Stats> statsThe stats for each attribute. -
types
The types for each attribute. -
normalize
private final boolean normalizeIndicates if attributes have to be normalized or not.
-
-
Constructor Details
-
NaiveBayesClassifier
public NaiveBayesClassifier()Constructor. -
NaiveBayesClassifier
public NaiveBayesClassifier(boolean normalize)Constructor- Parameters:
normalize
- indicates if attributes have to be normalized
-
-
Method Details
-
train
Description copied from interface:Classifier
Trains the classifier.- Specified by:
train
in interfaceClassifier<U>
- Parameters:
trainSet
- the training set.
-
computeScores
Description copied from interface:Classifier
Computes the scores for an individual instance (once the training has been done).- Specified by:
computeScores
in interfaceClassifier<U>
- Parameters:
instance
- the individual instance.- Returns:
- A score for each class.
-
computeScore
Description copied from interface:Classifier
Gets the score for an individual pattern in a certain category.- Specified by:
computeScore
in interfaceClassifier<U>
- Parameters:
instance
- the pattern.category
- the class.- Returns:
- the score.
-
classify
Description copied from interface:Classifier
Obtains the most likely class for a certain instance.- Specified by:
classify
in interfaceClassifier<U>
- Parameters:
instance
- the individual instance.- Returns:
- The most likely class.
-