plot_splits¶
yohou.plotting.plot_splits(y, splitter, *, X_actual=None, train_color=None, test_color=None, train_name='Train', test_name='Test', 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
|
train_name
|
str
|
Legend label for the train segments. |
"Train"
|
test_name
|
str
|
Legend label for the test segments. |
"Test"
|
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.
If the splitter produces no splits for the given |
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 ¶
Source code in src/yohou/plotting/model_selection.py
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 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 | |
Tutorials¶
The following example notebooks use this component:
-
CV Splitters
Demonstrate ExpandingWindowSplitter and SlidingWindowSplitter for temporal cross-validation with configurable test_size, stride, and fold visualisation.
-
How to Visualize Model Selection Results
Visualise CV fold geometry with expanding and sliding window splitters and hyperparameter search results with plot_splits and plot_cv_results_scatter.
-
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.