in causalml/inference/tree/models.py [0:0]
def fillTree(self, X, treatment, y, tree):
""" Fill the data into an existing tree.
This is a lower-level function to execute on the tree filling task.
Args
----
X : ndarray, shape = [num_samples, num_features]
An ndarray of the covariates used to train the uplift model.
treatment : array-like, shape = [num_samples]
An array containing the treatment group for each unit.
y : array-like, shape = [num_samples]
An array containing the outcome of interest for each unit.
tree : object
object of DecisionTree class
Returns
-------
self : object
"""
# Current Node Summary for Validation Data Set
currentNodeSummary = self.tree_node_summary(treatment, y,
min_samples_treatment=0,
n_reg=0,
parentNodeSummary=None)
tree.nodeSummary = currentNodeSummary
# Divide sets for child nodes
X_l, X_r, w_l, w_r, y_l, y_r = self.divideSet(X, treatment, y, tree.col, tree.value)
# recursive call for each branch
if tree.trueBranch is not None:
self.fillTree(X_l, w_l, y_l, tree.trueBranch)
if tree.falseBranch is not None:
self.fillTree(X_r, w_r, y_r, tree.falseBranch)
# Update Information
# matchScore
matchScore = (currentNodeSummary[tree.bestTreatment][0] - currentNodeSummary[self.control_name][0])
tree.matchScore = round(matchScore, 4)
tree.summary['matchScore'] = round(matchScore, 4)
# Samples, Group_size
tree.summary['samples'] = len(y)
tree.summary['group_size'] = ''
for treatment_group in currentNodeSummary:
tree.summary['group_size'] += ' ' + treatment_group + ': ' + str(currentNodeSummary[treatment_group][1])
# classProb
if tree.results is not None:
tree.results = self.uplift_classification_results(treatment, y)
return self