Struct rammer::HSModel [−][src]
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
Create a new empty model, with no training data.
let model = HSModel::new(); //returns an empty model.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 patternBuilder 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 patternCreate a HSModel from a ham_bow and a spam_bow.
let model = HSModel::from_bows(ham_bow, spam_bow);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]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");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
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 RefUnwindSafe for HSModel
impl UnwindSafe for HSModel
Blanket Implementations
Mutably borrows from an owned value. Read more