-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLeaf.cpp
More file actions
45 lines (40 loc) · 1.08 KB
/
Leaf.cpp
File metadata and controls
45 lines (40 loc) · 1.08 KB
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
#include "Leaf.h"
#include "global.h"
//effects of removing a leaf node
void Leaf::cut()
{
--numberOfNodes;
}
//prints classification of examples in leaf
void Leaf::printTree(unsigned int d)
{
if(classification == -1)
cout << ": no class";
else
cout << ": " << attributes[k].second[classification];
}
//output C++ code representing decision tree
void Leaf::recursiveSave(ofstream &treeWriter, unsigned int depth)
{
for(unsigned int i = 0; i < depth; ++i)
treeWriter << " ";
if(classification == -1)
treeWriter << " if(((*i)[" << k << "]).compare(\"no class\") == 0)" << endl;
else
treeWriter << " if(((*i)[" << k << "]).compare(\"" << attributes[k].second[classification] << "\") == 0)" << endl;
for(unsigned int i = 0; i < depth; ++i)
treeWriter << " ";
treeWriter << " ++correct;" << endl;
for(unsigned int i = 0; i < depth; ++i)
treeWriter << " ";
treeWriter << " else" << endl;
for(unsigned int i = 0; i < depth; ++i)
treeWriter << " ";
treeWriter << " ++incorrect;" << endl;
}
Leaf::Leaf()
{
}
Leaf::~Leaf()
{
}