Struggling to build a decision tree

This is my first time I need to build a decision tree. I've been working all day trying to make this, but yet still am nowhere. I think I need a recursive method, but am not able to find or define one.


Node class (header)
1
2
3
4
5
6
7
8
9
10
11
12
13
  class Node {
public:
    //variables
    Node* parent;
    map<string, double> probs;
    map<string, Node*> children;
    vector<vector<string> > t;
    string s;

    //functions
    Node(vector<vector<string> >);
    ~Node();
};


Tree::expandExternal

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
 void Tree::expandExternal(const Position& p) {
    Node* a;
    a = p.v;
    map<string, vector<vector<string>>> m = split(a->t);
    map<string, Node*> nodeMap;
    vector<vector<string>> tempTable;

    for (auto const &ent : m) {
        tempTable = ent.second;
        Node* n = new Node(ent.second);
        n->parent = a;
        n->s = ent.first;
        n->t = ent.second;
        nodeMap[ent.first] = n;
        print(tempTable);
    }
    a->children = nodeMap;
}


DTree::Learn
1
2
3
4
void DTree::learn(vector<vector<string>>& table) {
    addRoot(table);
    recursive(root);
}


DTree::recursive
1
2
3
4
5
6
7
8
9
10
11
void DTree::recursive(Node* p) {
    if (!checkLastColumn(p->t)) {
        expandExternal(p);
        for(auto const &ent : p->children){
        recursive(ent.second);
        }
    else {
        //is the leaf node filled with "ja" (yes) or "nee" (no)
        }
    }
}
Last edited on
- only upload your source code (*.cpp and *.h) and input data. I have no use for your binaries (object files, exe)
- the code in the zip is not the same that you've posted.
- ¿what's your problem?
Be careful of people posting .exe files. Some nasty stuff going around, maybe they are trying to find another way to spread it.
I'm having a decision tree at the moment. I will upload my code here for others to learn from if I have a bit more free time.

I know it is not recommended to share .exe files because it can be anything. I just zipped the map out of Documents->VS->Projects, maybe I should have only upload the .cpp files and the header file.
Topic archived. No new replies allowed.