-
Notifications
You must be signed in to change notification settings - Fork 0
/
id3.h
68 lines (50 loc) · 1.76 KB
/
id3.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
//
// id3.h
// VoterMLA
//
// Created by MD Shihabul Kabir on 12/3/16.
// Copyright © 2016 MD Shihabul Kabir. All rights reserved.
//
#ifndef id3_h
#define id3_h
#include "county.h"
#include <vector>
//ID3 Decision Learning Tree Namespace
namespace ItreeAlgo {
//set a sentinel value that will be used to check whether an attribute was used to split
const float SENTINEL = -9999.9999;
//Node Structure to build and traverse the tree
struct Itree{
//members
Itree* leftBin;
Itree* rightBin;
//int to store the attribute
int attr;
std::vector<CountyStruct::County>bin;
public:
//constructor
Itree(int at, Itree* first = nullptr, Itree* second = nullptr){
//initialize members
attr = at;
leftBin = first;
rightBin = second;
}
};
//Data Structure to process ID3 algorithm
class ID3{
public:
//method to return value with number of democrats and republicans
std::pair<int,int> getPercentages(std::vector<CountyStruct::County>&counties);
//method to get entropy of the data
float entropyData(std::pair<int,int>info);
//method to get entropy of the attribute
float entropyAttr(std::pair<int,int>info, int dataTotal);
//method to get the best split
int bestSplit(std::vector<CountyStruct::County> counties,std::vector<float>&splits);
//method to make the tree
Itree* makeTree(std::vector<CountyStruct::County>&counties,std::vector<float>splits);
//method to predict given a county
int predict(CountyStruct::County& aCounty,Itree* headptr);
};
}
#endif /* id3_h */