wink-naive-bayes-text-classifier
Advanced tools
Comparing version 1.0.1 to 1.1.0
{ | ||
"name": "wink-naive-bayes-text-classifier", | ||
"version": "1.0.1", | ||
"version": "1.1.0", | ||
"description": "Configurable Naive Bayes Classifier for text with cross-validation support", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -95,4 +95,17 @@ | ||
#### predict( input ) | ||
Predicts the label for the `input`. | ||
Predicts the label for the `input`. If it is unable to predict then it returns a value **`'unknown'`**. | ||
#### computeOdds( input ) | ||
Computes the log base-2 of odds of every label for the `input`; and returns the array of `[ label, odds ]` in descending | ||
order of `odds`. Here is an example of the returned array: | ||
```javascript | ||
[ | ||
[ 'prepay', 12.052329801050742 ], | ||
[ 'autoloan', -0.5258305619141836 ] | ||
] | ||
``` | ||
If it is unable to make prediction then it returns a value **`[ [ 'unknown', 0 ] ]`**. | ||
#### exportJSON() | ||
@@ -99,0 +112,0 @@ The learning can be exported as JSON text that may be saved in a file. |
@@ -298,9 +298,9 @@ // wink-naive-bayes-text-classifier | ||
// #### Predict | ||
// #### compute odds | ||
// Predicts the potential **label** for the given `input`, provided learnings | ||
// have been consolidated. If all the `input` tokens have never been seen | ||
// in past (i.e. absent in learnings), then the predicted label is `unknown`. | ||
// It throws error if the learnings have not been consolidated. | ||
var predict = function ( input ) { | ||
// Computes odds for every **label** for the given `input`, provided learnings | ||
// have been consolidated. They are sorted in descending order of their odds. | ||
// It throws error if the learnings have not been consolidated. Note, the odds | ||
// is actually the **log2** of odds. | ||
var computeOdds = function ( input ) { | ||
// Predict only if learnings have been consolidated! | ||
@@ -322,5 +322,17 @@ if ( !consolidated ) { | ||
// otherwise return the corresponding label. | ||
return ( ( allOdds[ 0 ][ 1 ] ) ? allOdds[ 0 ][ 0 ] : unknown ); | ||
return ( ( allOdds[ 0 ][ 1 ] ) ? allOdds : [ [ unknown, 0 ] ] ); | ||
}; | ||
// #### Predict | ||
// Predicts the potential **label** for the given `input`, provided learnings | ||
// have been consolidated. If all the `input` tokens have never been seen | ||
// in past (i.e. absent in learnings), then the predicted label is `unknown`. | ||
// It throws error if the learnings have not been consolidated. | ||
var predict = function ( input ) { | ||
// Contains label & the corresponding odds pairs. | ||
var allOdds = computeOdds( input ); | ||
return ( allOdds[ 0 ][ 0 ] ); | ||
}; | ||
// #### Stats | ||
@@ -522,2 +534,3 @@ | ||
methods.consolidate = consolidate; | ||
methods.computeOdds = computeOdds; | ||
methods.predict = predict; | ||
@@ -524,0 +537,0 @@ methods.stats = stats; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
61500
497
131