openGPMP
Open Source Mathematics Package
|
#include <bayes_clf.hpp>
Public Member Functions | |
BayesMultiNom (double alpha_param=1.0, bool fit_prior_param=true, const std::vector< double > &class_prior={}) | |
Constructor for BayesMultiNom class. More... | |
~BayesMultiNom () | |
Destructor for BayesMultiNom class. More... | |
void | train (const std::vector< std::vector< size_t >> &data, const std::vector< std::string > &labels) |
Train the classifier with a set of labeled data. More... | |
std::string | predict (const std::vector< size_t > &new_data) 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 for the Multinomial distribution. More... | |
bool | fit_prior |
Flag indicating whether to learn class prior probabilities during training. More... | |
std::unordered_map< std::string, double > | class_probs |
Map storing the probabilities of each class. More... | |
std::unordered_map< std::string, std::vector< double > > | feature_probs |
Map storing the probabilities of features for each class. More... | |
std::vector< double > | class_log_prior |
Vector storing the logarithm of the class prior probabilities. More... | |
Definition at line 245 of file bayes_clf.hpp.
gpmp::ml::BayesMultiNom::BayesMultiNom | ( | double | alpha_param = 1.0 , |
bool | fit_prior_param = true , |
||
const std::vector< double > & | class_prior = {} |
||
) |
Constructor for BayesMultiNom class.
alpha_param | Additive smoothing parameter |
fit_prior_param | Whether to learn class prior probabilities or not |
class_prior | Prior probabilities of the classes |
Definition at line 344 of file bayes_clf.cpp.
gpmp::ml::BayesMultiNom::~BayesMultiNom | ( | ) |
void gpmp::ml::BayesMultiNom::display | ( | ) | const |
Display the learned probabilities.
Definition at line 441 of file bayes_clf.cpp.
std::string gpmp::ml::BayesMultiNom::predict | ( | const std::vector< size_t > & | new_data | ) | const |
Predict the class of a new data point.
new_data | A vector of size_t representing the features of the new data point |
Definition at line 420 of file bayes_clf.cpp.
void gpmp::ml::BayesMultiNom::train | ( | const std::vector< std::vector< size_t >> & | 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 354 of file bayes_clf.cpp.
Referenced by main().
gpmp::ml::BayesMultiNom::alpha |
Additive smoothing parameter for the Multinomial distribution.
Definition at line 251 of file bayes_clf.hpp.
gpmp::ml::BayesMultiNom::class_log_prior |
Vector storing the logarithm of the class prior probabilities.
Used for faster computation during prediction
Definition at line 277 of file bayes_clf.hpp.
gpmp::ml::BayesMultiNom::class_probs |
Map storing the probabilities of each class.
The key is the class label (string), and the value is the probability (double).
Definition at line 264 of file bayes_clf.hpp.
gpmp::ml::BayesMultiNom::feature_probs |
Map storing the probabilities of features for each class.
The key is the class label (string), and the value is a vector of feature probabilities.
Definition at line 271 of file bayes_clf.hpp.
gpmp::ml::BayesMultiNom::fit_prior |
Flag indicating whether to learn class prior probabilities during training.
Definition at line 257 of file bayes_clf.hpp.