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).
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> ArchivePointee for T
impl<T> ArchivePointee for T
Source§type ArchivedMetadata = ()
type ArchivedMetadata = ()
Source§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
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> LayoutRaw for T
impl<T> LayoutRaw for T
Source§fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
Source§impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
Source§unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
Source§fn resolve_niched(out: Place<NichedOption<T, N1>>)
fn resolve_niched(out: Place<NichedOption<T, N1>>)
out indicating that a T is niched.