pub struct HSModel {
pub ham_bow: BagOfWords,
pub spam_bow: BagOfWords,
}Expand description
A model which contains 2 BagOfWords, one containing known spam, and the other known ham.
let ham_bow = BagOfWords::from("hello there how are you");
let spam_bow = BagOfWords::from("I have an offer you won't be able to pass up!!!");
let model = HSModel::new().add_spam_bow(spam_bow).add_ham_bow(ham_bow);Fields§
§ham_bow: BagOfWordsBagOfWords that are known to be found in non-spam (ham) text.
spam_bow: BagOfWordsBagOfWords that are know to be found in spam text.
Implementations§
Source§impl HSModel
impl HSModel
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new empty model, with no training data.
let model = HSModel::new(); //returns an empty model.Sourcepub fn add_spam_bow(self, spam_bow: BagOfWords) -> Self
pub fn add_spam_bow(self, spam_bow: BagOfWords) -> Self
Builder pattern for adding a spam_bow with the combine method.
let model = HSModel::new().add_spam_bow(spam_bow).add_ham_bow(ham_bow); //builder patternSourcepub fn add_ham_bow(self, ham_bow: BagOfWords) -> Self
pub fn add_ham_bow(self, ham_bow: BagOfWords) -> Self
Builder pattern for adding a ham_bow with the combine method.
let model = HSModel::new().add_ham_bow(ham_bow).add_spam_bow(spam_bow); //builder patternSourcepub fn from_bows(ham_bow: BagOfWords, spam_bow: BagOfWords) -> Self
pub fn from_bows(ham_bow: BagOfWords, spam_bow: BagOfWords) -> Self
Create a HSModel from a ham_bow and a spam_bow.
let model = HSModel::from_bows(ham_bow, spam_bow);Sourcepub fn text_spam_probability(&self, text: &str) -> Probability
pub fn text_spam_probability(&self, text: &str) -> Probability
Returns the probability that a slice of text is spam, based on the model. Read about how this is calulated here on the Naive Bayes Spam Filtering Wikipedia Page
let spam_probability = model.text_spam_probability("Respond fast! I have an offer of a lifetime!"); // return value between [0.0, 1.0]Sourcepub fn write_to_json(&self, file_path: &str) -> Option<()>
pub fn write_to_json(&self, file_path: &str) -> Option<()>
Serializse HSModel to a compact json string and write it to file_path. This write is destructive.
model.write_to_json("test_resources/test_models/model.json").expect("Write unsucessful");Sourcepub fn read_from_json(file_path: &str) -> Option<Self>
pub fn read_from_json(file_path: &str) -> Option<Self>
read a json string from file_path and deserialize it to HSModel.
let model = HSModel::read_from_json("test_resources/test_models/model.json").unwrap();Trait Implementations§
Source§impl<'de> Deserialize<'de> for HSModel
impl<'de> Deserialize<'de> for HSModel
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl Freeze for HSModel
impl RefUnwindSafe for HSModel
impl Send for HSModel
impl Sync for HSModel
impl Unpin for HSModel
impl UnwindSafe for HSModel
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
Mutably borrows from an owned value. Read more