pub struct NaiveBayes { /* private fields */ }Expand description
Naive Bayes classifier
Implementations§
Source§impl Classifier
impl Classifier
Sourcepub fn new() -> Classifier
pub fn new() -> Classifier
Creates a new classifier
Sourcepub fn add_document_tokenized(&mut self, document: &Vec<String>, label: &String)
pub fn add_document_tokenized(&mut self, document: &Vec<String>, label: &String)
Takes a document that has been tokenized into a vector of strings
and a label and adds the document to the list of documents that the
classifier is aware of and will train on next time the train() method is called
Sourcepub fn add_document(&mut self, document: &String, label: &String)
pub fn add_document(&mut self, document: &String, label: &String)
Takes a document and a label and tokenizes the document by
breaking on whitespace characters. The document is added to the list
of documents that the classifier is aware of and will train on next time
the train() method is called
Sourcepub fn add_documents(&mut self, examples: &Vec<(String, String)>)
pub fn add_documents(&mut self, examples: &Vec<(String, String)>)
Adds a list of (document, label) tuples to the classifier
Sourcepub fn add_documents_tokenized(&mut self, examples: &Vec<(Vec<String>, String)>)
pub fn add_documents_tokenized(&mut self, examples: &Vec<(Vec<String>, String)>)
Adds a list of (tokenized document, label) tuples to the classifier
Sourcepub fn get_labels(&self) -> Vec<String>
pub fn get_labels(&self) -> Vec<String>
Gets a vector of all of the labels that the classifier has seen so far
Sourcepub fn set_smoothing(&mut self, smoothing: f64)
pub fn set_smoothing(&mut self, smoothing: f64)
Sets the smoothing value (must be greater than 0.0)
Sourcepub fn classify_tokenized(&self, document: &Vec<String>) -> String
pub fn classify_tokenized(&self, document: &Vec<String>) -> String
Takes an unlabeled document that has been tokenized into a vector of strings and then computes a classifying label for the document
Sourcepub fn classify(&self, document: &String) -> String
pub fn classify(&self, document: &String) -> String
Takes an unlabeled document and tokenizes it by breaking on spaces and then computes a classifying label for the document
Sourcepub fn get_document_probabilities_tokenized(
&self,
document: &Vec<String>,
) -> Vec<(String, f64)>
pub fn get_document_probabilities_tokenized( &self, document: &Vec<String>, ) -> Vec<(String, f64)>
Similar to classify but instead of returning a single label, returns all labels and the probabilities of each one given the document
Sourcepub fn get_document_probabilities(
&self,
document: &String,
) -> Vec<(String, f64)>
pub fn get_document_probabilities( &self, document: &String, ) -> Vec<(String, f64)>
Similar to classify but instead of returning a single label, returns all labels and the probabilities of each one given the document
Sourcepub fn from_json(encoded: &str) -> Classifier
pub fn from_json(encoded: &str) -> Classifier
Builds a new classifier from a JSON string
Trait Implementations§
Source§impl Clone for Classifier
impl Clone for Classifier
Source§fn clone(&self) -> Classifier
fn clone(&self) -> Classifier
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for Classifier
impl Debug for Classifier
Source§impl Decodable for Classifier
impl Decodable for Classifier
Auto Trait Implementations§
impl Freeze for Classifier
impl RefUnwindSafe for Classifier
impl Send for Classifier
impl Sync for Classifier
impl Unpin for Classifier
impl UnwindSafe for Classifier
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit)