TimeSliceCrossValidator.split#
- TimeSliceCrossValidator.split(X, y=None)[source]#
Generate train/test indices for each time-slice split.
This implementation selects rows by date masks so that all coordinate levels (e.g., multiple geos) for the selected date ranges are included in each fold. It returns integer positions suitable for use with
DataFrame.iloc.- Parameters:
- X
pd.DataFrame Feature matrix containing the date column.
- y
pd.Series, optional Target variable. Not used but included for scikit-learn API compatibility.
- X
- Yields:
- train_idx
np.ndarray Integer indices for training rows in this fold.
- test_idx
np.ndarray Integer indices for test rows in this fold.
- train_idx
- Raises:
ValueErrorIf no splits are possible with the given parameters.
Examples
>>> cv = TimeSliceCrossValidator( ... n_init=10, forecast_horizon=5, date_column="date" ... ) >>> for train_idx, test_idx in cv.split(X, y): ... X_train, X_test = X.iloc[train_idx], X.iloc[test_idx] ... y_train, y_test = y.iloc[train_idx], y.iloc[test_idx]