Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add number_samples to XGBoost ML Models #398

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions eland/ml/transformers/xgboost.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,11 @@ def extract_node_id(self, node_id: str, curr_tree: int) -> int:
)

def build_leaf_node(self, row: pd.Series, curr_tree: int) -> TreeNode:
return TreeNode(node_idx=row["Node"], leaf_value=[float(row["Gain"])])
return TreeNode(
node_idx=row["Node"],
leaf_value=[float(row["Gain"])],
number_samples=int(row["Cover"]),
)

def build_tree_node(self, row: pd.Series, curr_tree: int) -> TreeNode:
node_index = row["Node"]
Expand All @@ -103,6 +107,7 @@ def build_tree_node(self, row: pd.Series, curr_tree: int) -> TreeNode:
right_child=self.extract_node_id(row["No"], curr_tree),
threshold=float(row["Split"]),
split_feature=self.get_feature_id(row["Feature"]),
number_samples=int(row["Cover"]),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is gonna work.

cover is a float. I don't know how they calculate cover related to the total number of samples that hit the tree. The docs indicate its the average of the total number of samples effected by the split.

I wonder if cover * number of features ~= The total number of docs? Can you investigate and confirm?

)

def build_tree(self, nodes: List[TreeNode]) -> Tree:
Expand Down Expand Up @@ -238,7 +243,9 @@ def build_leaf_node(self, row: pd.Series, curr_tree: int) -> TreeNode:
return super().build_leaf_node(row, curr_tree)
leaf_val = [0.0] * self._num_classes
leaf_val[curr_tree % self._num_classes] = float(row["Gain"])
return TreeNode(node_idx=row["Node"], leaf_value=leaf_val)
return TreeNode(
node_idx=row["Node"], leaf_value=leaf_val, number_samples=int(row["Cover"])
)

def determine_target_type(self) -> str:
return "classification"
Expand Down