public class NaiveBayes extends java.lang.Object implements SoftClassifier<double[]>
For a general purpose naive Bayes classifier without any assumptions
about the underlying distribution of each variable, we don't provide
a learning method to infer the variable distributions from the training data.
Instead, the users can fit any appropriate distributions on the data by
themselves with various Distribution
classes. Although the predict(double[])
method takes an array of double values as a general form of independent variables,
the users are free to use any discrete distributions to model categorical or
ordinal random variables.
Distribution
,
LDA
,
QDA
,
RDA
,
Serialized FormConstructor and Description |
---|
NaiveBayes(double[] priori,
smile.stat.distribution.Distribution[][] condprob)
Constructor of general naive Bayes classifier.
|
NaiveBayes(double[] priori,
smile.stat.distribution.Distribution[][] condprob,
smile.util.IntSet labels)
Constructor of general naive Bayes classifier.
|
Modifier and Type | Method and Description |
---|---|
int |
predict(double[] x)
Predict the class of an instance.
|
int |
predict(double[] x,
double[] posteriori)
Predict the class of an instance.
|
double[] |
priori()
Returns a priori probabilities.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
applyAsDouble, applyAsInt, f, predict
public NaiveBayes(double[] priori, smile.stat.distribution.Distribution[][] condprob)
priori
- the priori probability of each class.condprob
- the conditional distribution of each variable in
each class. In particular, condprob[i][j] is the conditional
distribution P(xj | class i).public NaiveBayes(double[] priori, smile.stat.distribution.Distribution[][] condprob, smile.util.IntSet labels)
priori
- the priori probability of each class.condprob
- the conditional distribution of each variable in
each class. In particular, condprob[i][j] is the conditional
distribution P(xj | class i).labels
- class labelspublic double[] priori()
public int predict(double[] x)
predict
in interface Classifier<double[]>
x
- the instance to be classified.public int predict(double[] x, double[] posteriori)
predict
in interface SoftClassifier<double[]>
x
- the instance to be classified.posteriori
- the array to store a posteriori probabilities on output.