8 std::vector<std::vector<size_t>> bernoulli_train_data = {
15 std::vector<std::string> bernoulli_labels = {
"spam",
"ham",
"spam",
"ham"};
18 bernoulli_clf.train(bernoulli_train_data, bernoulli_labels);
20 std::vector<size_t> bernoulli_new_data = {1, 0, 0};
21 std::string bernoulli_prediction =
22 bernoulli_clf.predict(bernoulli_new_data);
24 std::cout <<
"Predicted Class (BayesBernoulli): " << bernoulli_prediction
28 bernoulli_clf.display();
31 std::vector<std::vector<double>> clf_train_data = {
38 std::vector<std::string> clf_labels = {
"classA",
44 bayes_clf.
train(clf_train_data, clf_labels);
46 std::vector<double> bayes_clf_new_data = {2.0, 3.0, 4.0};
47 std::string bayes_clf_prediction = bayes_clf.predict(bayes_clf_new_data);
49 std::cout <<
"Predicted Class (BayesClf): " << bayes_clf_prediction <<
"\n";
55 std::vector<std::vector<double>> gauss_train_data = {
62 std::vector<std::string> gauss_labels = {
"classX",
68 gauss_clf.
train(gauss_train_data, gauss_labels);
70 std::vector<double> gauss_new_data = {2.3, 3.7, 4.5};
71 std::string gauss_prediction = gauss_clf.
predict(gauss_new_data);
73 std::cout <<
"Predicted Class (BayesGauss): " << gauss_prediction <<
"\n";
79 std::vector<std::vector<size_t>> multinom_train_data = {
86 std::vector<std::string> multinom_labels = {
"classA",
92 multinom_clf.
train(multinom_train_data, multinom_labels);
94 std::vector<size_t> multinom_new_data = {2, 3, 4};
95 std::string multinom_prediction = multinom_clf.predict(multinom_new_data);
97 std::cout <<
"Predicted Class (BayesMultiNom): " << multinom_prediction
101 multinom_clf.display();
Bayes Classifier Class based on assumptions of independence.
void train(const std::vector< std::vector< double >> &data, const std::vector< std::string > &labels)
Train the classifier with a set of labeled data.
void display() const
Display the learned probabilities.
std::string predict(const std::vector< double > &newData) const
Predict the class of a new data point.
void train(const std::vector< std::vector< double >> &data, const std::vector< std::string > &labels)
Train the classifier with a set of labeled data.
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.