pub struct NaiveBayes { /* private fields */ }
Implementations§
Source§impl NaiveBayes
impl NaiveBayes
Sourcepub fn new() -> NaiveBayes
pub fn new() -> NaiveBayes
creates a new instance of a NaiveBayes
classifier.
Examples found in repository?
examples/example.rs (line 15)
14fn main() {
15 let mut nb = NaiveBayes::new();
16 nb.train(&to_vec("great product"), &"positive".to_string());
17 nb.train(
18 &to_vec("the protection level is poor"),
19 &"negative".to_string(),
20 );
21 nb.train(
22 &to_vec("this is a great band I love them"),
23 &"positive".to_string(),
24 );
25 nb.train(
26 &to_vec("never buy this product it is too bad"),
27 &"negative".to_string(),
28 );
29 nb.train(&to_vec("i love the shoes"), &"positive".to_string());
30 nb.train(
31 &to_vec("good product happy with the purchase"),
32 &"positive".to_string(),
33 );
34 let to_classify: Vec<String> = to_vec("I love it is great");
35 let classification = nb.classify(&to_classify);
36 print!("classification = {:?}", classification);
37}
Sourcepub fn train(&mut self, data: &Vec<String>, label: &String)
pub fn train(&mut self, data: &Vec<String>, label: &String)
trains the model with a Vec<String>
of tokens, associating it with a String
label.
Examples found in repository?
examples/example.rs (line 16)
14fn main() {
15 let mut nb = NaiveBayes::new();
16 nb.train(&to_vec("great product"), &"positive".to_string());
17 nb.train(
18 &to_vec("the protection level is poor"),
19 &"negative".to_string(),
20 );
21 nb.train(
22 &to_vec("this is a great band I love them"),
23 &"positive".to_string(),
24 );
25 nb.train(
26 &to_vec("never buy this product it is too bad"),
27 &"negative".to_string(),
28 );
29 nb.train(&to_vec("i love the shoes"), &"positive".to_string());
30 nb.train(
31 &to_vec("good product happy with the purchase"),
32 &"positive".to_string(),
33 );
34 let to_classify: Vec<String> = to_vec("I love it is great");
35 let classification = nb.classify(&to_classify);
36 print!("classification = {:?}", classification);
37}
Sourcepub fn classify(&mut self, data: &Vec<String>) -> HashMap<String, f64>
pub fn classify(&mut self, data: &Vec<String>) -> HashMap<String, f64>
classify a Vec<String>
of tokens returning a map of tokens and probabilities
as keys and values, respectively.
Examples found in repository?
examples/example.rs (line 35)
14fn main() {
15 let mut nb = NaiveBayes::new();
16 nb.train(&to_vec("great product"), &"positive".to_string());
17 nb.train(
18 &to_vec("the protection level is poor"),
19 &"negative".to_string(),
20 );
21 nb.train(
22 &to_vec("this is a great band I love them"),
23 &"positive".to_string(),
24 );
25 nb.train(
26 &to_vec("never buy this product it is too bad"),
27 &"negative".to_string(),
28 );
29 nb.train(&to_vec("i love the shoes"), &"positive".to_string());
30 nb.train(
31 &to_vec("good product happy with the purchase"),
32 &"positive".to_string(),
33 );
34 let to_classify: Vec<String> = to_vec("I love it is great");
35 let classification = nb.classify(&to_classify);
36 print!("classification = {:?}", classification);
37}
Auto Trait Implementations§
impl Freeze for NaiveBayes
impl RefUnwindSafe for NaiveBayes
impl Send for NaiveBayes
impl Sync for NaiveBayes
impl Unpin for NaiveBayes
impl UnwindSafe for NaiveBayes
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