jsat.classifiers.bayesian
Class NaiveBayes
- java.lang.Object
-
- jsat.classifiers.bayesian.NaiveBayes
-
- All Implemented Interfaces:
- java.io.Serializable, java.lang.Cloneable, Classifier, Parameterized
public class NaiveBayes extends java.lang.Object implements Classifier, Parameterized
Provides an implementation of the Naive Bayes classifier that assumes numeric features come from some continuous probability distribution. By default this implementation restricts itself to only theGaussiandistribution, and becomes Gaussian Naive Bayes. Other distributions are supported, and aKernelDensityEstimatorcan be used as well.
By default, this implementation assumes that the input vectors are sparse and the distribution will only be estimated by the non-zero values, and features that are zero will be ignored during prediction time. This should be turned off when using dense data by callingsetSparceInput(boolean)
Naive Bayes assumes that all attributes are perfectly independent.- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class and Description static classNaiveBayes.NumericalHandelingThere are multiple ways of handling numerical attributes.
-
Field Summary
Fields Modifier and Type Field and Description static NaiveBayes.NumericalHandelingdefaultHandlingThe default method of handling numeric attributes isNaiveBayes.NumericalHandeling.NORMAL.
-
Constructor Summary
Constructors Constructor and Description NaiveBayes()Creates a new Gaussian Naive Bayes classifierNaiveBayes(NaiveBayes.NumericalHandeling numericalHandling)Creates a new Naive Bayes classifier that uses the specific method for handling numeric features.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description CategoricalResultsclassify(DataPoint data)Performs classification on the given data point.NaiveBayesclone()NaiveBayes.NumericalHandelinggetNumericalHandling()Returns the method used to handle numerical attributesbooleanisSparceInput()Returns true if the Classifier assumes that data points are sparce.voidsetNumericalHandling(NaiveBayes.NumericalHandeling numericalHandling)Sets the method used by this instance for handling numerical attributes.voidsetSparceInput(boolean sparceInput)Tells the Naive Bayes classifier to assume the importance of sparseness in the numerical values.booleansupportsWeightedData()Indicates whether the model knows how to train using weighted data points.voidtrain(ClassificationDataSet dataSet, boolean parallel)Trains the classifier and constructs a model for classification using the given data set.-
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface jsat.classifiers.Classifier
train
-
Methods inherited from interface jsat.parameters.Parameterized
getParameter, getParameters
-
-
-
-
Field Detail
-
defaultHandling
public static final NaiveBayes.NumericalHandeling defaultHandling
The default method of handling numeric attributes isNaiveBayes.NumericalHandeling.NORMAL.
-
-
Constructor Detail
-
NaiveBayes
public NaiveBayes(NaiveBayes.NumericalHandeling numericalHandling)
Creates a new Naive Bayes classifier that uses the specific method for handling numeric features.- Parameters:
numericalHandling- the method to use for numeric features
-
NaiveBayes
public NaiveBayes()
Creates a new Gaussian Naive Bayes classifier
-
-
Method Detail
-
setNumericalHandling
public void setNumericalHandling(NaiveBayes.NumericalHandeling numericalHandling)
Sets the method used by this instance for handling numerical attributes. This has no effect on an already trained classifier, but will change the result if trained again.- Parameters:
numericalHandling- the method to use for numerical attributes
-
getNumericalHandling
public NaiveBayes.NumericalHandeling getNumericalHandling()
Returns the method used to handle numerical attributes- Returns:
- the method used to handle numerical attributes
-
isSparceInput
public boolean isSparceInput()
Returns true if the Classifier assumes that data points are sparce.- Returns:
- true if the Classifier assumes that data points are sparce.
- See Also:
setSparceInput(boolean)
-
setSparceInput
public void setSparceInput(boolean sparceInput)
Tells the Naive Bayes classifier to assume the importance of sparseness in the numerical values. This means that values of zero will be ignored in computation and classification.
This allows faster, more efficient computation of results if the data points are indeed sparce. This will also produce different results. This value should not be changed after training and before classification.- Parameters:
sparceInput- true to assume sparseness in the data, false to ignore it and assume zeros are meaningful values.- See Also:
isSparceInput()
-
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.
-
clone
public NaiveBayes clone()
- Specified by:
clonein interfaceClassifier- Overrides:
clonein classjava.lang.Object
-
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
-
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.
-
-
DataMelt 3.0 © DataMelt by jWork.ORG