in causalml/inference/tree/uplift.pyx [0:0]
def fillTree(self, X, treatment_idx, 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_idx : array-like, shape = [num_samples]
An array containing the treatment group index 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_idx, y,
min_samples_treatment=0,
n_reg=0,
parentNodeSummary=None)
tree.nodeSummary = currentNodeSummary
# Divide sets for child nodes
if tree.trueBranch or tree.falseBranch:
X_l, X_r, w_l, w_r, y_l, y_r = self.divideSet(X, treatment_idx, 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[0][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, summary in zip(self.classes_, currentNodeSummary):
tree.summary['group_size'] += ' ' + treatment_group + ': ' + str(summary[1])
# classProb
if tree.results is not None:
tree.results = self.uplift_classification_results(treatment_idx, y)
return self