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>attributesList of attributes.private java.util.List<java.lang.Integer>classesList of classes.private java.util.List<java.lang.Double[][]>frequenciesA list of matrices which contains the information for each attribute in the training set.private static intMEANConstant index for the mean.private booleannormalizeIndicates if attributes have to be normalized or not.private static intNUMCONTNumber of parameters in .private intnumInstancesThe number of patterns.private java.util.List<java.lang.Double>prioriTimes each class appears in the training set.private static intSIGMAConstant index for the variance.private java.util.List<es.uam.eps.ir.ranksys.core.util.Stats>statsThe stats for each attribute.private booleantrainedIndicates if the training of the classifier has been done.private java.util.List<FeatureType>typesThe types for each attribute. -
Constructor Summary
Constructors Constructor Description NaiveBayesClassifier()Constructor.NaiveBayesClassifier(boolean normalize)Constructor -
Method Summary
Modifier and Type Method Description intclassify(Instance<U> instance)Obtains the most likely class for a certain instance.doublecomputeScore(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).voidtrain(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:ClassifierTrains the classifier.- Specified by:
trainin interfaceClassifier<U>- Parameters:
trainSet- the training set.
-
computeScores
Description copied from interface:ClassifierComputes the scores for an individual instance (once the training has been done).- Specified by:
computeScoresin interfaceClassifier<U>- Parameters:
instance- the individual instance.- Returns:
- A score for each class.
-
computeScore
Description copied from interface:ClassifierGets the score for an individual pattern in a certain category.- Specified by:
computeScorein interfaceClassifier<U>- Parameters:
instance- the pattern.category- the class.- Returns:
- the score.
-
classify
Description copied from interface:ClassifierObtains the most likely class for a certain instance.- Specified by:
classifyin interfaceClassifier<U>- Parameters:
instance- the individual instance.- Returns:
- The most likely class.
-