Skip to content

Commit 366182d

Browse files
committed
_
1 parent adfb611 commit 366182d

3 files changed

Lines changed: 34 additions & 36 deletions

File tree

examples/02_data_ops/1130_choices.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,10 +279,10 @@
279279
# durations or not.
280280
#
281281
# For example if we wanted to include only the encoder and classifier and hide
282-
# the times:
282+
# the fitting time:
283283

284284
# %%
285-
search.plot_results(show_choices=["encoder", "classifier"], show_times=False)
285+
search.plot_results(show_choices=["encoder", "classifier"], show_times=["score"])
286286

287287
# %%
288288
# In this example, we've seen how to use skrub's ``choose_from`` objects to tune

skrub/_data_ops/_estimator.py

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1379,7 +1379,7 @@ def plot_results(
13791379
min_score=None,
13801380
show_scores=None,
13811381
show_choices=None,
1382-
show_times=True,
1382+
show_times=None,
13831383
):
13841384
"""Create a parallel coordinate plot of the cross-validation results.
13851385
@@ -1407,38 +1407,34 @@ def plot_results(
14071407
(e.g. "alpha" in ``choose_float(0.0, 1.0, name="alpha")``).
14081408
By default all are shown.
14091409
1410-
show_times : bool, optional, default=True
1411-
Whether to show fit and score time or not.
1410+
show_times : list of str, optional
1411+
List of durations to show. Available times are ["fit", "score"].
1412+
By default both are shown.
14121413
14131414
Returns
14141415
-------
14151416
Plotly Figure
14161417
"""
14171418

1418-
# Check that requested show_scores and show_choices (if any) are available
1419-
1420-
if isinstance(show_scores, str):
1421-
show_scores = [show_scores]
1422-
if show_scores is not None:
1423-
available_scores = self._get_score_names()
1424-
missing_scores = set(show_scores).difference(available_scores)
1425-
if missing_scores:
1426-
raise ValueError(
1427-
"The following scores were requested in show_scores "
1428-
f"but do not exist in the results:\n{missing_scores}.\n"
1429-
f"The available scores are:\n{available_scores}."
1430-
)
1431-
if isinstance(show_choices, str):
1432-
show_choices = [show_choices]
1433-
if show_choices is not None:
1434-
available_choices = self._get_choice_names()
1435-
missing_choices = set(show_choices).difference(available_choices)
1436-
if missing_choices:
1437-
raise ValueError(
1438-
"The following choices (params) were requested in show_choices "
1439-
f"but do not exist in the results:\n{missing_choices}.\n"
1440-
f"The available choices are: {available_choices}."
1441-
)
1419+
# Check that requested show_scores, show_choices, and show_times
1420+
# (if any) are available
1421+
1422+
def _check(requested, available, name):
1423+
if isinstance(requested, str):
1424+
requested = [requested]
1425+
if requested is not None:
1426+
missing = set(requested).difference(available)
1427+
if missing:
1428+
raise ValueError(
1429+
f"The following {name} were requested in show_{name} "
1430+
f"but do not exist in the results:\n{missing}.\n"
1431+
f"The available {name} are:\n{available}."
1432+
)
1433+
return requested
1434+
1435+
show_scores = _check(show_scores, self._get_score_names(), "scores")
1436+
show_choices = _check(show_choices, self._get_choice_names(), "choices")
1437+
show_times = _check(show_times, ["fit", "score"], "times")
14421438

14431439
# Prepare the figure data
14441440

@@ -1461,8 +1457,11 @@ def plot_results(
14611457
if col_meta["type"] == "choice":
14621458
if show_choices is not None and col_meta["name"] not in show_choices:
14631459
to_drop.add(col_name)
1464-
time_cols = {"mean_fit_time", "mean_score_time"}
1465-
to_drop = (to_drop - time_cols) if show_times else (to_drop | time_cols)
1460+
for meth in ["fit", "score"]:
1461+
if show_times is None or meth in show_times:
1462+
to_drop.discard(f"mean_{meth}_time")
1463+
else:
1464+
to_drop.add(f"mean_{meth}_time")
14661465
to_show = set(cv_results.columns) - to_drop
14671466

14681467
# Find rows to show based on min_score

skrub/_data_ops/tests/test_parallel_coord.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ def classif_grid_search():
181181
(
182182
None,
183183
None,
184-
True,
184+
None,
185185
[
186186
"cols",
187187
"add",
@@ -195,21 +195,20 @@ def classif_grid_search():
195195
(
196196
"accuracy",
197197
["cols", "add"],
198-
False,
198+
"fit",
199199
[
200200
"cols",
201201
"add",
202+
"fit time",
202203
"mean_test_accuracy",
203204
],
204205
),
205206
(
206207
[],
207208
"add",
208-
True,
209+
[],
209210
[
210211
"add",
211-
"score time",
212-
"fit time",
213212
],
214213
),
215214
],

0 commit comments

Comments
 (0)