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

Improve _ctreeviz_univar() #227

Merged
merged 9 commits into from Jan 5, 2023
4 changes: 3 additions & 1 deletion dtreeviz/trees.py
Expand Up @@ -1498,14 +1498,16 @@ def _ctreeviz_univar(shadow_tree,

splits = [node.split() for node in shadow_tree.internal]
splits = sorted(splits)
bins = [ax.get_xlim()[0]] + splits + [ax.get_xlim()[1]]

if 'splits' in show: # this gets the horiz bars showing prediction region
pred_box_height = .07 * ax.get_ylim()[1]
bins = [ax.get_xlim()[0]] + splits + [ax.get_xlim()[1]]
for i in range(len(bins) - 1):
left = bins[i]
right = bins[i + 1]
inrange = y_train[(X_train >= left) & (X_train <= right)]
if 0 == len(inrange):
parrt marked this conversation as resolved.
Show resolved Hide resolved
continue
values, counts = np.unique(inrange, return_counts=True)
pred = values[np.argmax(counts)]
rect = patches.Rectangle((left, 0), (right - left), pred_box_height, linewidth=.3,
Expand Down