|
149 | 149 | # plots in the figure.
|
150 | 150 |
|
151 | 151 | # %% tags=["solution"]
|
152 |
| -import numpy as np |
| 152 | +# import numpy as np |
153 | 153 | from matplotlib import cm
|
154 | 154 |
|
155 |
| -classes = np.unique(tree.classes_) |
156 | 155 | _, axs = plt.subplots(ncols=3, nrows=1, sharey=True, figsize=(12, 5))
|
157 | 156 | plt.suptitle("Predicted probabilities for decision tree model", y=1.05)
|
158 | 157 | plt.subplots_adjust(bottom=0.45)
|
159 | 158 |
|
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( |
163 | 162 | tree,
|
164 | 163 | data_test,
|
165 | 164 | response_method="predict_proba",
|
166 | 165 | class_of_interest=class_of_interest,
|
167 |
| - ax=axs[idx], |
| 166 | + ax=ax, |
168 | 167 | vmin=0,
|
169 | 168 | vmax=1,
|
170 | 169 | )
|
171 |
| - axs[idx].scatter( |
| 170 | + ax.scatter( |
172 | 171 | data_test["Culmen Length (mm)"].loc[target_test == class_of_interest],
|
173 | 172 | data_test["Culmen Depth (mm)"].loc[target_test == class_of_interest],
|
174 | 173 | marker="o",
|
175 | 174 | c="w",
|
176 | 175 | edgecolor="k",
|
177 | 176 | )
|
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)") |
180 | 180 |
|
181 | 181 | ax = plt.axes([0.15, 0.14, 0.7, 0.05])
|
182 | 182 | plt.colorbar(
|
183 | 183 | cm.ScalarMappable(cmap="viridis"), cax=ax, orientation="horizontal"
|
184 | 184 | )
|
185 |
| -_ = plt.title("Probability") |
| 185 | +_ = ax.set_title("Class probability") |
186 | 186 |
|
187 | 187 | # %% [markdown] tags=["solution"]
|
188 | 188 | # ```{note}
|
|
0 commit comments