Package com.namsor.oss.classify.bayes
Class NaiveBayesClassifierLevelDBLaplacedImpl
- java.lang.Object
-
- com.namsor.oss.classify.bayes.AbstractNaiveBayesImpl
-
- com.namsor.oss.classify.bayes.AbstractNaiveBayesClassifierImpl
-
- com.namsor.oss.classify.bayes.AbstractNaiveBayesClassifierLevelDBImpl
-
- com.namsor.oss.classify.bayes.NaiveBayesClassifierLevelDBLaplacedImpl
-
- All Implemented Interfaces:
INaiveBayesClassifier
public class NaiveBayesClassifierLevelDBLaplacedImpl extends AbstractNaiveBayesClassifierLevelDBImpl implements INaiveBayesClassifier
Naive Bayes Classifier implementation with Laplace smoothing and LevelDB as key/value store. Learning is Synchronized but classification is not.- Author:
- elian carsenat, NamSor SAS
-
-
Field Summary
-
Fields inherited from class com.namsor.oss.classify.bayes.AbstractNaiveBayesClassifierImpl
orderByProba
-
-
Constructor Summary
Constructors Constructor Description NaiveBayesClassifierLevelDBLaplacedImpl(String classifierName, String[] categories, String rootPathWritable)
Create a Naive Bayes Classifier implementation with Laplace smoothing and LevelDB as key/value store, with defaults ALPHA=1 and VARIANT=falseNaiveBayesClassifierLevelDBLaplacedImpl(String classifierName, String[] categories, String rootPathWritable, double alpha, boolean variant)
Create a Naive Bayes Classifier implementation with Laplace smoothing and LevelDB as key/value store.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description IClassification
classify(Map<String,String> features, boolean explainData)
Predict most probable class, optionally returning the data needed for future explanation.void
learn(String category, Map<String,String> features, long weight)
Learn from features-
Methods inherited from class com.namsor.oss.classify.bayes.AbstractNaiveBayesClassifierLevelDBImpl
bytes, dbClose, dbCloseAndDestroy, dbSize, dumpDb, finalize, getDb
-
Methods inherited from class com.namsor.oss.classify.bayes.AbstractNaiveBayesClassifierImpl
getCategories, getClassifierName, learn, likelihoodsToProbas
-
Methods inherited from class com.namsor.oss.classify.bayes.AbstractNaiveBayesImpl
pathCategory, pathCategoryFeatureKey, pathCategoryFeatureKeyValue, pathFeatureKey, pathFeatureKeyCountValueTypes, pathFeatureKeyValue, pathGlobal, pathGlobalCountCategories
-
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.namsor.oss.classify.bayes.INaiveBayesClassifier
dbClose, dbCloseAndDestroy, dbSize, dumpDb, getCategories, learn
-
-
-
-
Constructor Detail
-
NaiveBayesClassifierLevelDBLaplacedImpl
public NaiveBayesClassifierLevelDBLaplacedImpl(String classifierName, String[] categories, String rootPathWritable, double alpha, boolean variant) throws PersistentClassifierException
Create a Naive Bayes Classifier implementation with Laplace smoothing and LevelDB as key/value store.- Parameters:
classifierName
- The classifier namecategories
- The classification categoriesrootPathWritable
- A writable path for LevelDB storagealpha
- The laplace Alpha, usually 1.0variant
- True for variant likelyhood[i] = 1d * ((categoryCount + alpha) / (globalCount + globalCountCategories * alpha)) * product;- Throws:
PersistentClassifierException
- The persistence error and cause
-
NaiveBayesClassifierLevelDBLaplacedImpl
public NaiveBayesClassifierLevelDBLaplacedImpl(String classifierName, String[] categories, String rootPathWritable) throws PersistentClassifierException
Create a Naive Bayes Classifier implementation with Laplace smoothing and LevelDB as key/value store, with defaults ALPHA=1 and VARIANT=false- Parameters:
classifierName
- The classifier namecategories
- The classification categoriesrootPathWritable
- A writable path for LevelDB storage- Throws:
PersistentClassifierException
- The persistence error and cause
-
-
Method Detail
-
learn
public void learn(String category, Map<String,String> features, long weight) throws ClassifyException
Description copied from interface:INaiveBayesClassifier
Learn from features- Specified by:
learn
in interfaceINaiveBayesClassifier
- Parameters:
category
- The categoryfeatures
- The featuresweight
- The weight- Throws:
ClassifyException
- The classification error and cause
-
classify
public IClassification classify(Map<String,String> features, boolean explainData) throws ClassifyException
Description copied from interface:INaiveBayesClassifier
Predict most probable class, optionally returning the data needed for future explanation.- Specified by:
classify
in interfaceINaiveBayesClassifier
- Parameters:
features
- The featuresexplainData
- If should return the data needed for future explanation- Returns:
- The most likely classes with probability and (optionally) the explanation
- Throws:
ClassifyException
- The classification error and cause
-
-