splitting¶
Shared positional IID, grouped and forward-only supervised split boundaries.
SplitMetadata
dataclass
¶
Validated positional entity or chronological block identifiers.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
kind
|
(iid, grouped, temporal)
|
Split protocol. |
'iid'
|
values
|
ndarray or None
|
Integer entity identifiers or chronologically ordered time-block codes.
Construct these with |
None
|
label_end_times
|
ndarray or None
|
Label-availability codes on the SAME ordered timeline as temporal
|
None
|
Source code in featcopilot/utils/splitting.py
make_cv_splits(y, task, n_splits, random_state, *, groups=None, timestamps=None, label_end_times=None, allow_constant_target=False)
¶
Build deterministic CV boundaries without entity or future-data overlap.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
y
|
array - like
|
One-dimensional supervised target, nonconstant unless regression
explicitly opts in through |
required |
task
|
(auto, classification, regression)
|
Explicit task or sklearn-compatible target inference. |
'auto'
|
n_splits
|
int
|
Requested maximum number of folds, at least two. Classification/group folds are capped by the smallest class count/number of groups. Temporal folds are capped by the available future blocks and may number one. Callers requiring an exact protocol count must check the returned length. |
required |
random_state
|
int
|
Nonnegative uint32 seed for IID folds. Group and temporal folds are deterministic; their partitions do not depend on the seed. |
required |
groups
|
array - like or None
|
Positionally aligned entity labels; every fold keeps groups disjoint. |
None
|
timestamps
|
array - like or None
|
Positionally aligned timestamps, mutually exclusive with groups. |
None
|
label_end_times
|
array - like or None
|
Label-availability times in the same domain/units as timestamps. Only training rows with end times STRICTLY BEFORE the earliest validation timestamp are retained. End times equal to that cutoff are purged. Validation blocks remain intact; purged rows are never moved to them. |
None
|
allow_constant_target
|
bool
|
Explicit opt-in for regression-only statistics such as target means.
Allows constant targets and constant/nonempty one-row training folds.
Classification coverage checks are never relaxed. Use explicit
|
False
|
Returns:
| Type | Description |
|---|---|
list of (ndarray, ndarray)
|
Training/validation integer row positions. IID/group validation folds cover all rows once. Temporal CV leaves an initial historical prefix unscored and partitions the remaining time blocks into disjoint windows. |
Raises:
| Type | Description |
|---|---|
ValueError
|
For invalid options/metadata or infeasible supervised partitions. |
Notes
Temporal CV reserves the first half of the time blocks for initial training, with a minimum of two blocks for two requested folds and four otherwise. Subsequent training rows come from expanding strictly earlier prefixes, filtered by label availability when supplied. There is no random fallback. This preserves the predictive engine's nested residual-split policy; these are not official provider-specific task folds.
Source code in featcopilot/utils/splitting.py
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 | |
make_holdout_splits(y, task, n_splits, random_state, *, test_size=0.25, groups=None, timestamps=None, label_end_times=None, allow_constant_target=False)
¶
Build repeated IID/group holdouts or disjoint forward validation windows.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
y
|
array - like
|
One-dimensional supervised target, nonconstant unless regression
explicitly opts in through |
required |
task
|
(auto, classification, regression)
|
Explicit task or sklearn-compatible target inference. |
'auto'
|
n_splits
|
int
|
Exact number of holdouts, at least one. |
required |
random_state
|
int
|
Seed for the first IID/group holdout. Subsequent seeds increment modulo 2**32. Temporal boundaries do not depend on random state. |
required |
test_size
|
float
|
Validation fraction in (0, 1), measured in IID rows or whole groups. For time blocks this is the approximate fraction of the first train-plus-validation prefix occupied by its validation window. |
0.25
|
groups
|
array - like or None
|
Positionally aligned entity labels. |
None
|
timestamps
|
array - like or None
|
Positionally aligned timestamps, mutually exclusive with groups. |
None
|
label_end_times
|
array - like or None
|
Positionally aligned label-availability times requiring timestamps in the same domain/units. Purge training rows whose end time is at or after the earliest validation timestamp, without changing validation blocks. |
None
|
allow_constant_target
|
bool
|
Allow constant regression targets and nonempty constant training folds. Classification checks remain strict. No mode allows empty training history after label-availability purging. |
False
|
Returns:
| Type | Description |
|---|---|
list of (ndarray, ndarray)
|
Training/validation row positions. Temporal windows have equal numbers of complete time blocks, cover the final blocks without overlap, and have expanding strictly earlier training prefixes. |
Raises:
| Type | Description |
|---|---|
ValueError
|
For invalid options/metadata or infeasible supervised partitions. |
Notes
Temporal window width is floor(B * test_size / (1 + (n_splits - 1) * test_size)), at least one block, where B is the number of distinct time blocks. Rounding can change the achieved fraction. At least four blocks and a two-block initial prefix are required. Repeated random holdouts may overlap; none is an unbiased external test once used for feature/hyperparameter selection.
Source code in featcopilot/utils/splitting.py
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 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 | |
validate_split_boundaries(train, test, *, groups=None, timestamps=None, label_end_times=None, n_rows=None)
¶
Validate an existing split without rewriting official row positions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
train
|
array - like
|
Nonempty, unique integer training-row positions. |
required |
test
|
array - like
|
Nonempty, unique integer validation/test-row positions, disjoint from training. Input arrays, order and membership are never modified. |
required |
groups
|
array - like or None
|
Full-dataset positional entity labels; entities must be disjoint. |
None
|
timestamps
|
array - like or None
|
Full-dataset prediction timestamps. Every training time must be strictly earlier than every test time; equal-time blocks cannot cross. |
None
|
label_end_times
|
array - like or None
|
Full-dataset label-availability times requiring matching timestamps. Every supplied training label must end strictly before the earliest test timestamp. Unsafe rows raise rather than being silently purged. |
None
|
n_rows
|
int or None
|
Dataset row count, otherwise inferred from metadata. With neither metadata nor a row count, only index structure/nonnegativity can be checked, not whether positions exceed the actual dataset length. |
None
|
Returns:
| Type | Description |
|---|---|
None
|
Successful validation. This function does not generate a replacement split or check target constancy/class coverage. |
Raises:
| Type | Description |
|---|---|
ValueError
|
For invalid/overlapping indices, invalid metadata or a violated split boundary. Combined group/time metadata remains explicitly unsupported. |
Source code in featcopilot/utils/splitting.py
validate_split_metadata(groups, timestamps, n_rows, *, label_end_times=None)
¶
Normalize split metadata without aligning pandas index labels.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
groups
|
array - like or None
|
One scalar, hashable entity identifier per row. |
required |
timestamps
|
array - like or None
|
One finite numeric or parseable datetime timestamp per row. Datetimes normalize to UTC; equal instants form one indivisible block. |
required |
n_rows
|
int
|
Expected positional length. |
required |
label_end_times
|
array - like or None
|
Positionally aligned label-availability times, requiring timestamps. Each must be at least its prediction timestamp. Both arrays must use the same time domain: finite real numbers in caller-specified matching units, or datetimes normalized to UTC. Numeric and datetime inputs cannot be mixed. Numeric units cannot be inferred from their values. |
None
|
Returns:
| Type | Description |
|---|---|
SplitMetadata
|
Entity codes or chronologically ordered time-block codes. |
Raises:
| Type | Description |
|---|---|
ValueError
|
For missing, malformed or mis-sized metadata, or simultaneous groups and timestamps. Joint group/temporal splitting is not implemented. |