-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.cpp
33 lines (31 loc) · 846 Bytes
/
test.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
/*
A Test Program for KNN on IRIS DataSet.
120 Data Points are used for training the KNN.
30 Data are then used for making predictions.
Accuracy is measured.
*/
#include<iostream>
#include "knn.h"
#include "iris.h"
using namespace std;
using knn::Classifier;
int main(){
Classifier csf(3); // Classifier having k=3 and Distance Metric is Euclidean(default)
csf.fit(120,4,iris_features,iris_labels); // Train the Model
int pd[30];
for(int i=0; i<30; i++){
pd[i] = csf.predict(iris_features[120+i]); // Store Predictions
}
cout << "Prediction:" << endl;
for(int i=0; i<30; i++){
cout << pd[i] << " ";
}
cout << endl;
cout << "Expected:" << endl;
for(int i=0; i<30; i++){
cout << iris_labels[120+i] << " ";
}
cout << endl;
cout << "Accuracy: " << knn::accuracy(pd,iris_labels+120,30) << endl; // Measure Accuracy
return 0;
}