-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtests.cpp
53 lines (45 loc) · 1.36 KB
/
tests.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
#include "linear_regression.h"
#include "primitives.h"
#include "rapidcsv.h"
using namespace std;
// Vector1D<double> y = Vector1D<double>(3);
// y[0] = 1;
// y[1] = 2;
// y[2] = 3;
// X[0][0] = 1;
// X[0][1] = 2;
// X[0][2] = 3;
// X[1][0] = 4;
// X[1][1] = 5;
// X[1][2] = 6;
// X[2][0] = 7;
// X[2][1] = 8;
// X[2][2] = 9;
// Vector1D<double> result = Vector1D<double>(3);
// linear_regression<double> lr = linear_regression<double>(3, 3);
// //test dot product , matrix and vector
// result = lr.predict(X);
// std::cout << result << std::endl;
// std::cout << X << std::endl;
// y = y+y; // vector addition
// std::cout << (y) << std::endl;
// rapidcsv::Document doc("../Salary_Data.csv");
// Vector1D<double> X = doc.GetColumn<double>("YearsExperience");
// std::cout<<Xn<<std::endl;
int main() {
rapidcsv::Document Xdoc("../Xarr.csv");
rapidcsv::Document Ydoc("../Yarr.csv");
Matrix<double> Xn = Matrix<double>(Xdoc.GetRowCount(), Xdoc.GetColumnCount());
Vector1D<double> y = Vector1D<double>(Ydoc.GetColumn<double>(0));
for (auto i = 0; i < Xdoc.GetRowCount(); i++) {
Xn[i] = Xdoc.GetRow<double>(i);
}
linear_regression<double> lr =
linear_regression<double>(Xdoc.GetColumnCount());
lr.fit(Xn, y, 10000);
cout << "The weights are" << endl;
cout << lr.getWeights() << endl;
cout << "The bias" << endl;
cout << lr.getBias() << endl;
return 0;
}