-
Notifications
You must be signed in to change notification settings - Fork 2
/
15 - FinalMain.cpp
73 lines (65 loc) · 2.15 KB
/
15 - FinalMain.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include<iostream>
#include<vector>
#include<fstream>
#include "14 - NaiveBayes.cpp"
#include "12 - Mathimp.cpp"
#include "13- preprocessing.cpp"
#include<ctime>
using namespace std;
int main()
{
std::srand (unsigned(std::time(0)));
std::ifstream in;
in.open("Tf Idf for cpp.csv");
NaiveBayes naive = NaiveBayes();
vector<vector<float>> dataset;
vector<float> row;
int index=0;
string temp,line;
float temp2;
while(std::getline(in,line))
{
std::cout<<index+1<<"\r";
std::cout.flush();
index++;
temp="";
for(std::size_t i=0;i<line.size();i++)
{
if(line[i]!=',')
{
temp = temp + line[i];
}
else
{
temp2 = std::stof(temp);
row.push_back(temp2);
temp="";
}
}
dataset.push_back(row);
row.clear();
}
cout<<"dataset size"<<dataset.size()<<","<<dataset[0].size()<<endl;
std::srand (unsigned(std::time(0)));
dataset = algMath::vect_Transpose(dataset);
std::random_shuffle (dataset.begin(),dataset.end());
dataset = algMath::vect_Transpose(dataset);
float percentage =70;
std::vector<std::vector<float>> training_data = vectorTrainSplit(dataset , percentage);
std::vector<std::vector<float>> testing_data = vectorTestSplit(dataset , 100 - percentage);
std::cout<< "testing Data Size is ( " << testing_data.size() << " , " <<testing_data[0].size()<<" )" <<std::endl;
std::cout<< "training Data Size is ( " << training_data.size() << " , " <<training_data[0].size()<<" )" <<std::endl;
naive.fit(training_data);
std::vector<float> predicitions;
testing_data = algMath::vect_Transpose(testing_data);
for(std::size_t i=0; i<testing_data.size(); i++ )
{
cout<<"Predicting..."<<"\r";
cout.flush();
auto index = naive.predict(testing_data[i]);
predicitions.push_back(index);
}
testing_data = algMath::vect_Transpose(testing_data);
std::cout<<"score is :" << vectMatchScore(testing_data[4],predicitions)<<std::endl;
return 0;
}