Commit 97ff316e authored by ahmedaj's avatar ahmedaj
Browse files

Depth reached for each tree

parent dea77701
......@@ -21,12 +21,13 @@ DecisionTree::DecisionTree(vector <vector<string>> data, int maxDepth, float fea
// }
this->maxDepth = maxDepth;
this->featureWeight = featureWeight;
this->root = train(data, featureType, 0.0, 0, maxDepth, featureWeight);
this->maxDepthReached = 0;
this->root = train(data, featureType, 0.0, &this->maxDepthReached, maxDepth, featureWeight);
// this->printTree(this->root, 0);
};
Node *train(vector <vector<string>> data, vector <FeatureType> featureType,
double parentEntropy, int currentDepth, int maxDepth, float featureWeight) {
double parentEntropy, int *currentDepth, int maxDepth, float featureWeight) {
std::pair<string, double> classificationAndEntropy = classifyWithEntropy(data);
string classification = classificationAndEntropy.first;
......@@ -38,7 +39,7 @@ Node *train(vector <vector<string>> data, vector <FeatureType> featureType,
informationGainFromParent = parentEntropy - originalEntropy;
}
if (currentDepth > maxDepth || originalEntropy == 0.0) {
if (*currentDepth > maxDepth || originalEntropy == 0.0) {
Node *leaf = new Node(NULL, NULL, NULL, true, classification, originalEntropy, informationGainFromParent);
return leaf;
......@@ -52,7 +53,7 @@ Node *train(vector <vector<string>> data, vector <FeatureType> featureType,
// cout<<"Finding best split"<<endl;
//find best split
BestSplitPoint bestSplit = findBestSplit(parentEntropy, currentDepth, potentialSplits, data,
BestSplitPoint bestSplit = findBestSplit(parentEntropy, *currentDepth, potentialSplits, data,
featureType);
//cout << "------ best split index "<<bestSplit.featureIdx<<endl;
......@@ -82,9 +83,10 @@ Node *train(vector <vector<string>> data, vector <FeatureType> featureType,
// cout<<"Next Train"<<endl;
//call train for left and right data
Node *leftNode = train(featureSplitData.dataTrue, featureType, originalEntropy, currentDepth + 1, maxDepth,
*currentDepth += 1;
Node *leftNode = train(featureSplitData.dataTrue, featureType, originalEntropy, currentDepth, maxDepth,
featureWeight);
Node *rightNode = train(featureSplitData.dataFalse, featureType, originalEntropy, currentDepth + 1, maxDepth,
Node *rightNode = train(featureSplitData.dataFalse, featureType, originalEntropy, currentDepth, maxDepth,
featureWeight);
......
......@@ -21,6 +21,7 @@ public:
Node *root;
int maxDepth;
int maxDepthReached;
float featureWeight;
......@@ -30,7 +31,7 @@ private:
};
Node *train(vector <vector<string>> data, vector <FeatureType> featureType,
double entropy, int currentDepth, int maxDepth, float featureWeight);
double entropy, int *currentDepth, int maxDepth, float featureWeight);
#endif //RACER_DECISIONTREE_HPP
......@@ -118,6 +118,8 @@ RandomForest::getForestPrediction(vector <string> test, RandomForest *forest, ve
sort(itr->second, test, features);
}
}
cout << "Maximum depth reached = "<<tree->maxDepthReached<< " ";
cout << endl;
}
//pick the biggest voted label
......@@ -200,7 +202,6 @@ vector <pair<int, double>> sort(vector<std::pair < int, double> > &M, vector <st
cout << features[it.first] << " is " << test[it.first]<< "(information gain: "<<it.second << "), ";
count++;
}
cout << endl;
return A;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment