Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

wink-naive-bayes-text-classifier

Package Overview
Dependencies
Maintainers
3
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

wink-naive-bayes-text-classifier - npm Package Compare versions

Comparing version 1.0.1 to 1.1.0

2

package.json
{
"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;

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc