plot_nested_splits¶
yohou.plotting.plot_nested_splits(y, outer_splitter, inner_splitter, *, outer_fold=-1, X_actual=None, train_color=None, test_color=None, outer_train_color=None, outer_test_color=None, train_name='Inner train', test_name='Inner validation', outer_train_name='Outer train (refit, best params)', outer_test_name='Outer test (scored)', show_legend=True, title=None, x_label=None, y_label=None, width=None, height=None, resampler=None, line_width=10.0, facet_n_cols=2)
¶
Plot a nested cross-validation as a timeline visualization.
Shows both levels of a nested cross-validation. The inner rows are the cross-validation carved from one outer fold's training window, which selects the hyperparameters. The outer row above them shows the full outer training window the model is then refit on with those hyperparameters, plus the outer test window it is scored on (held out from the inner tuning). The figure is generated from the splitters themselves, so it is faithful to actual splitting behavior rather than hand-drawn.
Parameters ¶
| Name | Type | Description | Default |
|---|---|---|---|
y
|
DataFrame
|
Target time series with mandatory "time" column. |
required |
outer_splitter
|
BaseSplitter
|
Splitter for the outer (evaluation) loop. |
required |
inner_splitter
|
BaseSplitter
|
Splitter for the inner (tuning) loop, applied to an outer fold's training slice. |
required |
outer_fold
|
int or all
|
Which outer fold to render. An integer selects a single outer fold (default
|
-1
|
X_actual
|
DataFrame or None
|
Actual features passed to |
None
|
train_color
|
str or None
|
Colors for the inner-train, inner-validation, outer-refit-train, and outer-test segments. If None, the first four colors from the yohou palette are used. |
None
|
test_color
|
str or None
|
Colors for the inner-train, inner-validation, outer-refit-train, and outer-test segments. If None, the first four colors from the yohou palette are used. |
None
|
outer_train_color
|
str or None
|
Colors for the inner-train, inner-validation, outer-refit-train, and outer-test segments. If None, the first four colors from the yohou palette are used. |
None
|
outer_test_color
|
str or None
|
Colors for the inner-train, inner-validation, outer-refit-train, and outer-test segments. If None, the first four colors from the yohou palette are used. |
None
|
train_name
|
str
|
Legend label for the inner training segments. |
"Inner train"
|
test_name
|
str
|
Legend label for the inner validation segments. |
"Inner validation"
|
outer_train_name
|
str
|
Legend label for the outer training window the model is refit on. |
"Outer train (refit, best params)"
|
outer_test_name
|
str
|
Legend label for the outer test window the refit model is scored on. |
"Outer test (scored)"
|
show_legend
|
bool
|
Whether to show the legend. |
True
|
title
|
str or None
|
Plot title. Defaults to "Nested Cross-Validation Splits". |
None
|
x_label
|
str or None
|
X-axis label. Defaults to "Time". |
None
|
y_label
|
str or None
|
Y-axis label. Defaults to "Fold". |
None
|
width
|
int or None
|
Plot width in pixels. |
None
|
height
|
int or None
|
Plot height in pixels. |
None
|
resampler
|
bool or widget or None
|
Enable plotly-resampler for large datasets. |
None
|
line_width
|
float
|
Width of the segment bars. |
10.0
|
facet_n_cols
|
int
|
Number of subplot columns when |
2
|
Returns ¶
| Type | Description |
|---|---|
Figure
|
Plotly figure object. |
Raises ¶
| Type | Description |
|---|---|
TypeError
|
If a splitter is not a |
ValueError
|
If |
Examples ¶
>>> import polars as pl
>>> from yohou.plotting import plot_nested_splits
>>> from yohou.model_selection import ExpandingWindowSplitter
>>> y = pl.DataFrame({
... "time": pl.date_range(pl.date(2020, 1, 1), pl.date(2020, 12, 31), "1d", eager=True),
... "value": list(range(366)),
... })
>>> fig = plot_nested_splits(
... y,
... ExpandingWindowSplitter(n_splits=3, test_size=30),
... ExpandingWindowSplitter(n_splits=3, test_size=20),
... )
>>> len(fig.data) > 0
True
See Also ¶
plot_splits: Plot a flat (single-level) CV.ExpandingWindowSplitter: Expanding window cross-validation.
Source Code ¶
Source code in src/yohou/plotting/model_selection.py
396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 | |