Package com.namsor.oss.classify.bayes
Class ClassificationExplainedImpl
- java.lang.Object
-
- com.namsor.oss.classify.bayes.ClassificationExplainedImpl
-
- All Implemented Interfaces:
IClassification
,IClassificationExplained
public class ClassificationExplainedImpl extends Object implements IClassificationExplained
The detailed explanation of a classification : - likelyhood values - likelyhood formulae (in a readable format) - likelyhood expressions (in a readable format) The toString() function generates a JavaScript that can interpreted- Author:
- elian
-
-
Constructor Summary
Constructors Constructor Description ClassificationExplainedImpl(IClassification classification, double[] likelyhoods, String[] likelyhoodFormulae, String[] likelyhoodExpressions)
Create an immutable detailed explanation of a classification :
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description IClassification
getClassification()
IClassProbability[]
getClassProbabilities()
The ordered classes and probabilities.Map<String,Long>
getExplanationData()
All the data needed to explain the results.Map<String,String>
getFeatures()
The input featuresdouble
getLaplaceSmoothingAlpha()
The alpha value used for Laplace smoothingString[]
getLikelyhoodExpressions()
For each likelyhood, get the expression ex.String[]
getLikelyhoodFormulae()
For each likelyhood, get the formula ex.double[]
getLikelyhoods()
Get the likelyhoods values, ex.boolean
isLaplaceSmoothed()
Is Laplace smoothed?boolean
isLaplaceSmoothedVariant()
If Laplace Smoothed With variant, then: likelyhood[i] = 1d * ((categoryCount + alpha) / (globalCount + globalCountCategories * alpha)) * product; otherwise: likelyhood[i] = 1d * categoryCount / globalCount * product;String
toString()
Print to String that can be interpreted as JavaScript and return the highest probability value
-
-
-
Constructor Detail
-
ClassificationExplainedImpl
public ClassificationExplainedImpl(IClassification classification, double[] likelyhoods, String[] likelyhoodFormulae, String[] likelyhoodExpressions)
Create an immutable detailed explanation of a classification :- Parameters:
classification
- The classification output and explainDatalikelyhoods
- The likelyhood valueslikelyhoodFormulae
- The likelyhood formulaelikelyhoodExpressions
- The likelyhood expressions
-
-
Method Detail
-
getClassification
public IClassification getClassification()
- Returns:
- the classification
-
getLikelyhoods
public double[] getLikelyhoods()
Description copied from interface:IClassificationExplained
Get the likelyhoods values, ex. 0.011806375442739082- Specified by:
getLikelyhoods
in interfaceIClassificationExplained
- Returns:
- the likelyhoods
-
getLikelyhoodFormulae
public String[] getLikelyhoodFormulae()
Description copied from interface:IClassificationExplained
For each likelyhood, get the formula ex. gL_cA_Yes / gL * ((gL_cA_Yes_fE_temp_is_Cool + alpha)/(gL_cA_Yes_fE_temp + ( gL_fE_temp_count * alpha )) * (gL_cA_Yes_fE_humidity_is_High + alpha)/(gL_cA_Yes_fE_humidity + ( gL_fE_humidity_count * alpha )) * (gL_cA_Yes_fE_outlook_is_Overcast + alpha)/(gL_cA_Yes_fE_outlook + ( gL_fE_outlook_count * alpha )) * (gL_cA_Yes_fE_wind_is_Strong + alpha)/(gL_cA_Yes_fE_wind + ( gL_fE_wind_count * alpha )) * 1 )- Specified by:
getLikelyhoodFormulae
in interfaceIClassificationExplained
- Returns:
- the likelyhoodFormulae
-
getLikelyhoodExpressions
public String[] getLikelyhoodExpressions()
Description copied from interface:IClassificationExplained
For each likelyhood, get the expression ex. 9 / 14 * ((3 + 1.0 )/(9 + ( 3 * 1.0 )) * (3 + 1.0 )/(9 + ( 2 * 1.0 )) * (4 + 1.0 )/(9 + ( 3 * 1.0 )) * (3 + 1.0 )/(9 + ( 2 * 1.0 )) * 1 )- Specified by:
getLikelyhoodExpressions
in interfaceIClassificationExplained
- Returns:
- the likelyhoodExpressions
-
getClassProbabilities
public IClassProbability[] getClassProbabilities()
Description copied from interface:IClassification
The ordered classes and probabilities.- Specified by:
getClassProbabilities
in interfaceIClassification
- Returns:
- the classProbabilities : class name and probability (possibly the last class is 'Other')
-
getExplanationData
public Map<String,Long> getExplanationData()
Description copied from interface:IClassification
All the data needed to explain the results.- Specified by:
getExplanationData
in interfaceIClassification
- Returns:
- the explanation : list of features and counts
-
isLaplaceSmoothed
public boolean isLaplaceSmoothed()
Description copied from interface:IClassification
Is Laplace smoothed?- Specified by:
isLaplaceSmoothed
in interfaceIClassification
- Returns:
- True if Laplace smoothed
-
isLaplaceSmoothedVariant
public boolean isLaplaceSmoothedVariant()
Description copied from interface:IClassification
If Laplace Smoothed With variant, then: likelyhood[i] = 1d * ((categoryCount + alpha) / (globalCount + globalCountCategories * alpha)) * product; otherwise: likelyhood[i] = 1d * categoryCount / globalCount * product;- Specified by:
isLaplaceSmoothedVariant
in interfaceIClassification
- Returns:
- If Laplace smothing variant used
-
getFeatures
public Map<String,String> getFeatures()
Description copied from interface:IClassification
The input features- Specified by:
getFeatures
in interfaceIClassification
- Returns:
- The input features
-
getLaplaceSmoothingAlpha
public double getLaplaceSmoothingAlpha()
Description copied from interface:IClassification
The alpha value used for Laplace smoothing- Specified by:
getLaplaceSmoothingAlpha
in interfaceIClassification
- Returns:
- The alpha value, usually 1.0
-
-