Struct classifier::NaiveBayes
[-] [+]
[src]
pub struct NaiveBayes { // some fields omitted }
Naive Bayes classifier
Methods
impl Classifier
fn new() -> Classifier
Creates a new classifier
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
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
fn add_documents(&mut self, examples: &Vec<(String, String)>)
Adds a list of (document, label) tuples to the classifier
fn add_documents_tokenized(&mut self, examples: &Vec<(Vec<String>, String)>)
Adds a list of (tokenized document, label) tuples to the classifier
fn get_labels(&self) -> Vec<String>
Gets a vector of all of the labels that the classifier has seen so far
fn set_smoothing(&mut self, smoothing: f64)
Sets the smoothing value (must be greater than 0.0)
fn train(&mut self)
Trains the classifier on the documents that have been observed so far
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
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
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
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
fn to_json(&self) -> String
Encodes the classifier as a JSON string.
fn from_json(encoded: &str) -> Classifier
Builds a new classifier from a JSON string