Nasty.Operations.Classification.NaiveBayes (Nasty v0.3.0)
View SourceGeneric Naive Bayes classifier for text classification.
Implements:
- Multinomial Naive Bayes algorithm
- Laplace (add-one) smoothing for unseen features
- Log probabilities to avoid numerical underflow
- Softmax for probability normalization
Summary
Functions
Evaluates a model on test data.
Predicts class probabilities for a feature vector.
Trains a Naive Bayes model from labeled feature vectors.
Functions
@spec evaluate(Nasty.AST.ClassificationModel.t(), [{map(), atom()}], atom()) :: map()
Evaluates a model on test data.
Returns accuracy and per-class precision, recall, and F1 metrics.
@spec predict(Nasty.AST.ClassificationModel.t(), map(), atom()) :: [ Nasty.AST.Classification.t() ]
Predicts class probabilities for a feature vector.
Uses log probabilities and softmax for numerical stability.
Returns
List of Classification structs sorted by confidence (highest first)
@spec train( [{map(), atom()}], keyword() ) :: Nasty.AST.ClassificationModel.t()
Trains a Naive Bayes model from labeled feature vectors.
Arguments
labeled_features- List of{feature_vector, class}tuplesopts- Training options
Options
:smoothing- Laplace smoothing parameter alpha (default: 1.0):feature_types- List of feature types used (for metadata)
Returns
ClassificationModel struct with learned parameters