-
Notifications
You must be signed in to change notification settings - Fork 0
/
experiment.cpp
36 lines (31 loc) · 1.19 KB
/
experiment.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include "instancepool.h"
#include "knnclassifier.h"
#include "nbclassifier.h"
#include "baselineclassifier.h"
#include "classifierevaluator.h"
#include <fstream>
#include <iostream>
#include <string>
using namespace std;
void printResults(const string& headerMessage, const ClassifierEvaluator& evaluator) {
cout << headerMessage << endl
<< "accuracy: " << evaluator.getAccuracy() << endl
<< "precision: " << evaluator.getPrecision() << endl
<< "recall: " << evaluator.getRecall() << endl << endl;
}
int main() {
ifstream trainingFile("training_data.txt");
ifstream testFile("test_data.txt");
InstancePool trainingPool, testPool;
trainingFile >> trainingPool;
testFile >> testPool;
KNNClassifier kNN;
ClassifierEvaluator kNNEvaluator(kNN, trainingPool, testPool);
printResults("kNN evaluation:", kNNEvaluator);
NaiveBayesClassifier nb;
ClassifierEvaluator nbEvaluator(nb, trainingPool, testPool);
printResults("Naive Bayes evaluation:", nbEvaluator);
BaselineClassifier base;
ClassifierEvaluator baseEvaluator(base, trainingPool, testPool);
printResults("Baseline evaluation:", baseEvaluator);
}