bayesian
A simple, fast Naive Bayes classifier with support for TF-IDF weighting and binary serialization.
Installation
Usage
Class labels can be any type that implements Eq + Hash + Clone (an enum is the most natural choice).
use Classifier;
TF-IDF
Plain Naive Bayes is always available. Call build_tfidf() to compute TF-IDF
weights from your training data and unlock the _tfidf family of methods.
You can continue learning and call build_tfidf() again at any time — it
recomputes from scratch without discarding raw counts.
classifier.learn; // accumulates both raw counts and TF samples
classifier.build_tfidf; // compute weights from all learned documents
let class = classifier.classify_tfidf;
let probs = classifier.prob_scores_tfidf;
let scores = classifier.log_scores_tfidf;
Serialization
Serialize to an in-memory binary blob or directly to a file.
// In-memory
let bytes = classifier.serialize.expect;
let restored = from_data.expect;
// File
classifier.serialize_to_file.expect;
let restored = from_file.expect;
serialize / from_data require C: serde::Serialize + serde::DeserializeOwned. Add
#[derive(serde::Serialize, serde::Deserialize)] to your class label type.