plot_splits¶
yohou.plotting.model_selection.plot_splits(y, splitter, *, X_actual=None, train_color=None, test_color=None, show_legend=True, title=None, x_label=None, y_label=None, width=None, height=None, resampler=None, line_width=10.0)
¶
Plot cross-validation splits as a timeline visualization.
Creates a horizontal bar chart showing train/test splits for each fold, useful for understanding temporal CV strategies like expanding or sliding windows.
Parameters¶
| Name | Type | Description | Default |
|---|---|---|---|
y
|
DataFrame
|
Target time series with mandatory "time" column. |
required |
splitter
|
BaseSplitter
|
A yohou splitter instance (e.g., ExpandingWindowSplitter, SlidingWindowSplitter). |
required |
X_actual
|
DataFrame or None
|
Actual features passed to |
None
|
train_color
|
str | None
|
Color for train segments. If None, uses first color from yohou palette. |
None
|
test_color
|
str | None
|
Color for test segments. If None, uses second color from yohou palette. |
None
|
show_legend
|
bool
|
Whether to show the legend. |
True
|
title
|
str | None
|
Plot title. Defaults to "Cross-Validation Splits". |
None
|
x_label
|
str | None
|
X-axis label. Defaults to "Time". |
None
|
y_label
|
str | None
|
Y-axis label. Defaults to "Fold". |
None
|
width
|
int | None
|
Plot width in pixels. |
None
|
height
|
int | None
|
Plot height in pixels. Defaults to 300 + n_splits * 30. |
None
|
resampler
|
bool | Literal['widget'] | None
|
Enable plotly-resampler for large datasets. |
None
|
line_width
|
float
|
Width of the train/test bars. |
10.0
|
Returns¶
| Type | Description |
|---|---|
Figure
|
Plotly figure object. |
Raises¶
| Type | Description |
|---|---|
TypeError
|
If y is not a Polars DataFrame or splitter is not a BaseSplitter. |
ValueError
|
If DataFrame is empty or missing 'time' column. |
Examples¶
>>> import polars as pl
>>> from yohou.plotting import plot_splits
>>> from yohou.model_selection import ExpandingWindowSplitter
>>> # Create sample data
>>> y = pl.DataFrame({
... "time": pl.date_range(pl.date(2020, 1, 1), pl.date(2020, 12, 31), "1d", eager=True),
... "value": list(range(366)),
... })
>>> # Create splitter and plot
>>> splitter = ExpandingWindowSplitter(n_splits=3, test_size=30)
>>> fig = plot_splits(y, splitter)
>>> len(fig.data) > 0
True
See Also¶
plot_cv_results_scatter : Plot hyperparameter search results.
ExpandingWindowSplitter : Expanding window cross-validation.
SlidingWindowSplitter : Sliding window cross-validation.
Source Code¶
Show/Hide source
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 | |
Tutorials¶
The following example notebooks use this component:
-
CV Splitters
Getting-Started
Demonstrate ExpandingWindowSplitter and SlidingWindowSplitter for temporal cross-validation with configurable test_size, stride, and fold visualisation.
-
Quickstart
Quickstart
Comprehensive end-to-end tour of yohou beyond the Getting Started tutorials, covering data loading, baseline forecasting, preprocessing pipelines, decomposition, cross-validation search, and interval prediction.
-
How to Visualize Model Selection Results
Visualization
Visualise CV fold geometry with expanding and sliding window splitters and hyperparameter search results with plot_splits and plot_cv_results_scatter.