pub struct CategorizationModel { /* private fields */ }Expand description
A trained categorization model.
Wraps a Multinomial Naive Bayes classifier trained on TF-IDF features extracted from transaction payee/narration text.
Implementations§
Source§impl CategorizationModel
impl CategorizationModel
Sourcepub fn train(directives: &[DirectiveWrapper]) -> Result<Self, MlError>
pub fn train(directives: &[DirectiveWrapper]) -> Result<Self, MlError>
Train a model from existing ledger directives.
Extracts (text, account) pairs from transactions where the second posting’s account is the categorization target. Requires at least 2 distinct categories with at least 1 transaction each.
§Errors
Returns MlError::InsufficientData if there aren’t enough transactions
or distinct categories to train a useful model.
Sourcepub fn predict(
&self,
narration: &str,
payee: Option<&str>,
) -> Vec<(String, f64)>
pub fn predict( &self, narration: &str, payee: Option<&str>, ) -> Vec<(String, f64)>
Predict the account for a transaction.
Returns predictions sorted by confidence (highest first). Each
prediction is an (account, probability) pair. The probabilities
are the class-conditional posteriors from the underlying
Multinomial Naive Bayes model (they sum to 1.0 across all
classes), so callers can treat them as honest scores.
Sourcepub const fn num_categories(&self) -> usize
pub const fn num_categories(&self) -> usize
Number of distinct categories the model was trained on.
Sourcepub fn vocab_size(&self) -> usize
pub fn vocab_size(&self) -> usize
Number of features (vocabulary size).