Skip to content

Commit 6e04ab0

Browse files
author
ArturoAmorQ
committed
Address Guillaume's comments
1 parent 62e6ef0 commit 6e04ab0

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

python_scripts/trees_sol_01.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -149,40 +149,40 @@
149149
# plots in the figure.
150150

151151
# %% tags=["solution"]
152-
import numpy as np
152+
# import numpy as np
153153
from matplotlib import cm
154154

155-
classes = np.unique(tree.classes_)
156155
_, axs = plt.subplots(ncols=3, nrows=1, sharey=True, figsize=(12, 5))
157156
plt.suptitle("Predicted probabilities for decision tree model", y=1.05)
158157
plt.subplots_adjust(bottom=0.45)
159158

160-
for idx, class_of_interest in enumerate(classes):
161-
axs[idx].set_title(f"Class {class_of_interest}")
162-
disp = DecisionBoundaryDisplay.from_estimator(
159+
for idx, (class_of_interest, ax) in enumerate(zip(tree.classes_, axs)):
160+
ax.set_title(f"Class {class_of_interest}")
161+
DecisionBoundaryDisplay.from_estimator(
163162
tree,
164163
data_test,
165164
response_method="predict_proba",
166165
class_of_interest=class_of_interest,
167-
ax=axs[idx],
166+
ax=ax,
168167
vmin=0,
169168
vmax=1,
170169
)
171-
axs[idx].scatter(
170+
ax.scatter(
172171
data_test["Culmen Length (mm)"].loc[target_test == class_of_interest],
173172
data_test["Culmen Depth (mm)"].loc[target_test == class_of_interest],
174173
marker="o",
175174
c="w",
176175
edgecolor="k",
177176
)
178-
axs[idx].set_xlabel("Culmen Length (mm)")
179-
axs[idx].set_ylabel("Culmen Depth (mm)" if idx == 0 else None)
177+
ax.set_xlabel("Culmen Length (mm)")
178+
if idx == 0:
179+
ax.set_ylabel("Culmen Depth (mm)")
180180

181181
ax = plt.axes([0.15, 0.14, 0.7, 0.05])
182182
plt.colorbar(
183183
cm.ScalarMappable(cmap="viridis"), cax=ax, orientation="horizontal"
184184
)
185-
_ = plt.title("Probability")
185+
_ = ax.set_title("Class probability")
186186

187187
# %% [markdown] tags=["solution"]
188188
# ```{note}

0 commit comments

Comments
 (0)