NaiveBayesTextClassifier
A multinomial Naive Bayes classifier for text classification. Uses Laplace smoothing and supports native acceleration for fast inference.Constructor
smoothing(optional): Laplace smoothing parameter (default: 1.0, minimum: 1e-9)
Methods
train()
Train the classifier on labeled examples.examples: Array of{ label: string, text: string }objects
classify()
Predict the most likely label for a text.text: The text to classify
predict()
Get ranked predictions with log probabilities for all labels.{ label: string, logProb: number } sorted by probability (descending)
Example:
evaluate()
Evaluate the classifier on test examples.examples: Test examples with known labels
labels()
Get all labels the classifier has learned.toJSON()
Serialize the classifier to JSON.fromSerialized()
Load a classifier from serialized data.payload: Serialized model data