Skip to content

Latest commit

 

History

History
98 lines (66 loc) · 4.13 KB

Classifier.md

File metadata and controls

98 lines (66 loc) · 4.13 KB

Classifier

new Classifier([model])

Param Type Default Description
[model] Model | Object
[model.nGramMin] int 1 Minimum n-gram size
[model.nGramMax] int 1 Maximum n-gram size
[model.vocabulary] Array | Set | false [] Terms mapped to indexes in the model data, set to false to store terms directly in the data entries
[model.data] Object {} Key-value store of labels and training data vectors

classifier.model : Model

Model instance

classifier.train(input, label) ⇒ this

Train the current model using an input string (or array of strings) and a corresponding label

Param Type Description
input string | Array String, or an array of strings
label string Corresponding label

classifier.predict(input, [maxMatches], [minimumConfidence]) ⇒ Array

Return an array of one or more Prediction instances

Param Type Default Description
input string Input string to make a prediction from
[maxMatches] int 1 Maximum number of predictions to return
[minimumConfidence] float 0.2 Minimum confidence required to include a prediction

classifier.splitWords(input) ⇒ Array

Split a string into an array of lowercase words, with all non-letter characters removed

Param Type
input string

classifier.tokenize(input) ⇒ Object

Create an object literal of unique tokens (n-grams) as keys, and their respective occurrences as values based on an input string, or array of words

Param Type
input string | Array

classifier.vectorize(tokens) ⇒ Object

Convert a tokenized object into a new object with all keys (terms) translated to their index in the returned vocabulary (which is also returned along with the object, with any new terms added to the end)

Param Type
tokens Object

classifier.cosineSimilarity(v1, v2) ⇒ float

Return the cosine similarity between two vectors

Param Type
v1 Object
v2 Object