-
Notifications
You must be signed in to change notification settings - Fork 0
/
noob_pandas.h
57 lines (51 loc) · 1.04 KB
/
noob_pandas.h
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
// SWAMI KARUPPASWAMI THUNNAI
#pragma once
#include <string>
#include <vector>
#include <fstream>
#include <typeinfo>
#include "json.h"
using json = nlohmann::json;
template <typename D, typename T>
class noob_pandas
{
private:
std::vector<std::vector<D>> X;
std::vector<T> y;
public:
noob_pandas(std::string data_set)
{
std::ifstream file;
file.open(data_set);
if (!file.is_open()) throw "Dataset cannot be opened!";
json j;
file >> j;
file.close();
unsigned long int max_index = j["max_index"];
for (unsigned long int i = 0; i < max_index; i++)
{
if (typeid(D).name() == typeid(std::string).name())
{
D x_val = j[std::to_string(i)]["X"];
std::vector<D> independent;
independent.push_back(x_val);
X.push_back(independent);
}
else
{
std::vector<D> independent = j[std::to_string(i)]["X"];
X.push_back(independent);
}
T dependent = j[std::to_string(i)]["y"];
y.push_back(dependent);
}
}
std::vector<std::vector<D>> get_X()
{
return X;
}
std::vector<T> get_y()
{
return y;
}
};