openGPMP
Open Source Mathematics Package
|
Bayes Classifier Class based on assumptions of independence. More...
#include <bayes_clf.hpp>
Public Member Functions | |
BayesClf (double alpha_param=1.0, bool fit_prior_param=true, const std::vector< double > &class_prior={}) | |
Constructor for BayesClf class. More... | |
~BayesClf () | |
Destructor for BayesClf class. More... | |
void | train (const std::vector< std::vector< double >> &data, const std::vector< std::string > &labels) |
Train the classifier with a set of labeled data. More... | |
std::string | predict (const std::vector< double > &newData) const |
Predict the class of a new data point. More... | |
void | display () const |
Display the learned probabilities. More... | |
Public Attributes | |
double | alpha |
Additive smoothing parameter. More... | |
bool | fit_prior |
Whether to learn class prior probabilities or not. More... | |
std::unordered_map< std::string, double > | class_probs |
Map of class labels to their probabilities. More... | |
std::unordered_map< std::string, std::vector< double > > | feature_probs |
Map of class labels to their feature probabilities. More... | |
std::vector< double > | class_log_prior |
Vector of class log priors. More... | |
Bayes Classifier Class based on assumptions of independence.
Definition at line 53 of file bayes_clf.hpp.
gpmp::ml::BayesClf::BayesClf | ( | double | alpha_param = 1.0 , |
bool | fit_prior_param = true , |
||
const std::vector< double > & | class_prior = {} |
||
) |
Constructor for BayesClf class.
alpha | Additive (Laplace/Lidstone) smoothing parameter |
fit_prior | Whether to learn class prior probabilities or not |
class_prior | Prior probabilities of the classes |
Definition at line 42 of file bayes_clf.cpp.
gpmp::ml::BayesClf::~BayesClf | ( | ) |
void gpmp::ml::BayesClf::display | ( | ) | const |
Display the learned probabilities.
Definition at line 135 of file bayes_clf.cpp.
std::string gpmp::ml::BayesClf::predict | ( | const std::vector< double > & | newData | ) | const |
Predict the class of a new data point.
newData | A vector of doubles representing the features of the new data point |
Definition at line 114 of file bayes_clf.cpp.
void gpmp::ml::BayesClf::train | ( | const std::vector< std::vector< double >> & | data, |
const std::vector< std::string > & | labels | ||
) |
Train the classifier with a set of labeled data.
data | A vector of vectors representing the training instances |
labels | A vector of strings representing the corresponding class labels |
Definition at line 52 of file bayes_clf.cpp.
Referenced by main().
double gpmp::ml::BayesClf::alpha |
Additive smoothing parameter.
Definition at line 58 of file bayes_clf.hpp.
std::vector<double> gpmp::ml::BayesClf::class_log_prior |
Vector of class log priors.
Definition at line 75 of file bayes_clf.hpp.
std::unordered_map<std::string, double> gpmp::ml::BayesClf::class_probs |
Map of class labels to their probabilities.
Definition at line 67 of file bayes_clf.hpp.
std::unordered_map<std::string, std::vector<double> > gpmp::ml::BayesClf::feature_probs |
Map of class labels to their feature probabilities.
Definition at line 71 of file bayes_clf.hpp.
bool gpmp::ml::BayesClf::fit_prior |
Whether to learn class prior probabilities or not.
Definition at line 63 of file bayes_clf.hpp.