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: BagOfWords

BagOfWords that are known to be found in non-spam (ham) text.

spam_bow: BagOfWords

BagOfWords 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 pattern

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 pattern

Create 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

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Returns the “default value” for a type. Read more

Deserialize this value from the given Serde deserializer. Read more

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The alignment of pointer.

The type for initializers.

Initializes a with the given initializer. Read more

Dereferences the given pointer. Read more

Mutably dereferences the given pointer. Read more

Drops the object pointed to by the given pointer. Read more

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.