Package com.namsor.oss.classify.bayes
Class NaiveBayesClassifierMapLaplacedImpl
- java.lang.Object
-
- com.namsor.oss.classify.bayes.AbstractNaiveBayesImpl
-
- com.namsor.oss.classify.bayes.AbstractNaiveBayesClassifierImpl
-
- com.namsor.oss.classify.bayes.AbstractNaiveBayesClassifierMapImpl
-
- com.namsor.oss.classify.bayes.NaiveBayesClassifierMapLaplacedImpl
-
- All Implemented Interfaces:
INaiveBayesClassifier
public class NaiveBayesClassifierMapLaplacedImpl extends AbstractNaiveBayesClassifierMapImpl implements INaiveBayesClassifier
Naive Bayes Classifier with Laplace smoothing and implementation with concurrent ConcurrentHashMap or persistent mapDB. The Laplace smoothing has two variants as per Sample1 and Sample2.- Author:
- elian carsenat, NamSor SAS
-
-
Field Summary
-
Fields inherited from class com.namsor.oss.classify.bayes.AbstractNaiveBayesClassifierImpl
orderByProba
-
-
Constructor Summary
Constructors Constructor Description NaiveBayesClassifierMapLaplacedImpl(String classifierName, String[] categories)
Create in-memory classifier using ConcurrentHashMap and defaults for Laplace smoothing (ALPHA=1 and VARIANT=false)NaiveBayesClassifierMapLaplacedImpl(String classifierName, String[] categories, double alpha, boolean variant)
Create a classifier with in-memory ConcurrentHashMap and Laplace parametersNaiveBayesClassifierMapLaplacedImpl(String classifierName, String[] categories, double alpha, boolean variant, String rootPathWritable)
Create persistent classifier using org.mapdb.HTreeMap and Laplace parametersNaiveBayesClassifierMapLaplacedImpl(String classifierName, String[] categories, String rootPathWritable)
Create persistent classifier using org.mapdb.HTreeMap and defaults for Laplace smoothing (ALPHA=1 and VARIANT=false)
-
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.AbstractNaiveBayesClassifierMapImpl
dbClose, dbCloseAndDestroy, dbSize, dumpDb, getDb, getRootPathWritable
-
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, finalize, 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
-
NaiveBayesClassifierMapLaplacedImpl
public NaiveBayesClassifierMapLaplacedImpl(String classifierName, String[] categories)
Create in-memory classifier using ConcurrentHashMap and defaults for Laplace smoothing (ALPHA=1 and VARIANT=false)- Parameters:
classifierName
- The classifier namecategories
- The classification categories
-
NaiveBayesClassifierMapLaplacedImpl
public NaiveBayesClassifierMapLaplacedImpl(String classifierName, String[] categories, double alpha, boolean variant)
Create a classifier with in-memory ConcurrentHashMap and Laplace parameters- Parameters:
classifierName
- The classifier namecategories
- The classification categoriesalpha
- The Laplace alpha, typically 1.0variant
- The Laplace variant
-
NaiveBayesClassifierMapLaplacedImpl
public NaiveBayesClassifierMapLaplacedImpl(String classifierName, String[] categories, double alpha, boolean variant, String rootPathWritable)
Create persistent classifier using org.mapdb.HTreeMap and Laplace parameters- Parameters:
classifierName
- The classifier namecategories
- The classification categoriesalpha
- The Laplace alpha, typically 1.0variant
- The Laplace variantrootPathWritable
- A writable directory for org.mapdb.HTreeMap storage
-
NaiveBayesClassifierMapLaplacedImpl
public NaiveBayesClassifierMapLaplacedImpl(String classifierName, String[] categories, String rootPathWritable)
Create persistent classifier using org.mapdb.HTreeMap and defaults for Laplace smoothing (ALPHA=1 and VARIANT=false)- Parameters:
classifierName
- The classifier namecategories
- The classification categoriesrootPathWritable
- A writable directory for org.mapdb.HTreeMap storage
-
-
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
-
-