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 up to top_n predictions sorted by confidence (highest first).
Each prediction is an (account, probability) pair.
Note: Confidence scores are not calibrated. The predicted class always
receives a confidence of 0.8 and all other classes receive 0.0.
Computing calibrated probabilities requires log-likelihood estimation,
which is a future enhancement.
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).
Auto Trait Implementations§
impl Freeze for CategorizationModel
impl RefUnwindSafe for CategorizationModel
impl Send for CategorizationModel
impl Sync for CategorizationModel
impl Unpin for CategorizationModel
impl UnsafeUnpin for CategorizationModel
impl UnwindSafe for CategorizationModel
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more