-
Notifications
You must be signed in to change notification settings - Fork 0
/
preprocessing.h
76 lines (60 loc) · 1.36 KB
/
preprocessing.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// SWAMI KARUPPASWAMI THUNNAI
#pragma once
#include <vector>
#include <set>
#include <map>
/*
Label Encoder: Encodes the label A,B,C to 0,1,2
i.e converts the categorical data into numerical values.
Written By: Visweswaran N, 2019-08-28
*/
template <typename T>
class LabelEncoder
{
private:
std::vector<T> label_vector;
std::vector<unsigned long int> encoded_vector;
std::map<T, unsigned long int> headers;
void fit();
void transform();
public:
LabelEncoder(std::vector<T> label_vector) : label_vector(label_vector) {}
std::vector<unsigned long int> fit_transorm();
};
/*
For standardization
-------------------
Formula:
z = (x - u) / s
Varaible names:
~~~~~~~~~~~~~~~~~~~~~~
u = mean
s = standard deviation
Written By: Visweswaran N, 2019-08-29
*/
class StandardScaler
{
private:
std::vector<double> array;
double u, s;
public:
StandardScaler(std::vector<double> array): array(array){}
std::vector<double> scale();
double inverse_scale(double z);
};
namespace preprocessing
{
std::vector<double> normalize(std::vector<double> array);
}
template <typename T>
class LabelBinarizer
{
private:
std::set<T> headers;
std::vector<T> data;
std::vector<std::vector<unsigned long int>> encoded_vector;
public:
LabelBinarizer(std::vector<T> data): data(data){}
std::vector<std::vector<unsigned long int>> fit();
std::vector<unsigned long int> predict(T value);
};