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 IClassificationgetClassification()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 featuresdoublegetLaplaceSmoothingAlpha()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.booleanisLaplaceSmoothed()Is Laplace smoothed?booleanisLaplaceSmoothedVariant()If Laplace Smoothed With variant, then: likelyhood[i] = 1d * ((categoryCount + alpha) / (globalCount + globalCountCategories * alpha)) * product; otherwise: likelyhood[i] = 1d * categoryCount / globalCount * product;StringtoString()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:IClassificationExplainedGet the likelyhoods values, ex. 0.011806375442739082- Specified by:
getLikelyhoodsin interfaceIClassificationExplained- Returns:
- the likelyhoods
-
getLikelyhoodFormulae
public String[] getLikelyhoodFormulae()
Description copied from interface:IClassificationExplainedFor 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:
getLikelyhoodFormulaein interfaceIClassificationExplained- Returns:
- the likelyhoodFormulae
-
getLikelyhoodExpressions
public String[] getLikelyhoodExpressions()
Description copied from interface:IClassificationExplainedFor 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:
getLikelyhoodExpressionsin interfaceIClassificationExplained- Returns:
- the likelyhoodExpressions
-
getClassProbabilities
public IClassProbability[] getClassProbabilities()
Description copied from interface:IClassificationThe ordered classes and probabilities.- Specified by:
getClassProbabilitiesin interfaceIClassification- Returns:
- the classProbabilities : class name and probability (possibly the last class is 'Other')
-
getExplanationData
public Map<String,Long> getExplanationData()
Description copied from interface:IClassificationAll the data needed to explain the results.- Specified by:
getExplanationDatain interfaceIClassification- Returns:
- the explanation : list of features and counts
-
isLaplaceSmoothed
public boolean isLaplaceSmoothed()
Description copied from interface:IClassificationIs Laplace smoothed?- Specified by:
isLaplaceSmoothedin interfaceIClassification- Returns:
- True if Laplace smoothed
-
isLaplaceSmoothedVariant
public boolean isLaplaceSmoothedVariant()
Description copied from interface:IClassificationIf Laplace Smoothed With variant, then: likelyhood[i] = 1d * ((categoryCount + alpha) / (globalCount + globalCountCategories * alpha)) * product; otherwise: likelyhood[i] = 1d * categoryCount / globalCount * product;- Specified by:
isLaplaceSmoothedVariantin interfaceIClassification- Returns:
- If Laplace smothing variant used
-
getFeatures
public Map<String,String> getFeatures()
Description copied from interface:IClassificationThe input features- Specified by:
getFeaturesin interfaceIClassification- Returns:
- The input features
-
getLaplaceSmoothingAlpha
public double getLaplaceSmoothingAlpha()
Description copied from interface:IClassificationThe alpha value used for Laplace smoothing- Specified by:
getLaplaceSmoothingAlphain interfaceIClassification- Returns:
- The alpha value, usually 1.0
-
-