Skip to content

Commit

Permalink
fix: correctly parse ensemble trees with only a subset of target feat…
Browse files Browse the repository at this point in the history
…ures
  • Loading branch information
iamDecode committed Jul 22, 2020
1 parent e03792a commit 4b59487
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion sklearn_pmml_model/tree/tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,16 @@ def construct_tree(node, classes, field_mapping, i=0):
if record_count is not None:
node_count_weighted = float(record_count)
node_count = int(node_count_weighted)
votes = [[[float(e.get('recordCount')) for e in node.findall('ScoreDistribution')]]]

def votesFor(target):
# Deal with case where targetfield a double, but ScoreDistribution value
# is an integer.
if isinstance(target, float) and target.is_integer():
return node.find(f"ScoreDistribution[@value='{target}']") or node.find(f"ScoreDistribution[@value='{int(target)}']")

return node.find(f"ScoreDistribution[@value='{target}']")

votes = [[[float(votesFor(c).get('recordCount')) if votesFor(c) is not None else 0.0 for c in classes]]]
else:
score = node.get('score')

Expand Down

0 comments on commit 4b59487

Please sign in to comment.