BaseActualTransformer¶
yohou.base.BaseActualTransformer
¶
Bases: _BaseTransformer
Base class for single-axis ("actual"-kind) time series transformers.
Yohou transformers operate on polars DataFrames with a mandatory
"time" column and support stateful windowing via observe,
rewind, observe_transform, and rewind_transform methods.
observe_transform observes new data and then transforms it, while
rewind_transform rewinds state to a window and then transforms it.
Attributes ¶
| Name | Type | Description |
|---|---|---|
feature_names_in_ |
list[str]
|
Names of the non-time columns seen during |
n_features_in_ |
int
|
Number of non-time columns seen during |
X_schema_ |
dict[str, DataType]
|
Column name to dtype mapping seen during |
interval_ |
str
|
Detected time interval of the training data (e.g., |
Notes ¶
Transformers can be stateful (observation_horizon > 0) or
stateless (observation_horizon == 0). Stateful transformers
maintain an internal memory buffer of the most recent
observation_horizon rows, which is updated by observe() and
replaced by rewind() (which sets the memory to the last
observation_horizon rows of the provided data).
All transformers preserve the "time" column through
transform() and inverse_transform().
See Also ¶
BaseForecastTransformer: Base class for X_forecast transformers.BaseForecaster: Base class for forecasters.LagTransformer: Creates lagged features from time series.SeasonalDifferencing: Stateful seasonal differencing transformer.
Source Code ¶
Source code in src/yohou/base/transformer.py
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 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 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 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 | |
Methods ¶
observation_horizon
property
¶
Get the number of time steps needed for stateful operations.
The observation horizon defines how many recent observations the transformer needs to maintain in its memory.
Returns ¶
| Type | Description |
|---|---|
int
|
Number of time steps to retain. |
Raises ¶
| Type | Description |
|---|---|
NotFittedError
|
If the transformer has not been fitted yet. |
fit(X, y=None, **params)
¶
Fit the transformer to input data.
Parameters ¶
| Name | Type | Description | Default |
|---|---|---|---|
X
|
DataFrame
|
Input time series with a |
required |
y
|
DataFrame or None
|
Ignored. Present for API compatibility. |
None
|
**params
|
dict
|
Metadata to route to nested estimators. |
{}
|
Returns ¶
| Type | Description |
|---|---|
self
|
The fitted transformer instance. |
Raises ¶
| Type | Description |
|---|---|
ValueError
|
If |
Source Code ¶
Source code in src/yohou/base/transformer.py
rewind(X)
¶
Rewind internal memory to the last observation_horizon rows.
Parameters ¶
| Name | Type | Description | Default |
|---|---|---|---|
X
|
DataFrame
|
Input time series with a |
required |
Returns ¶
| Type | Description |
|---|---|
self
|
The transformer with internal memory rewound to the last
|
Raises ¶
| Type | Description |
|---|---|
NotFittedError
|
If the transformer has not been fitted yet. |
ValueError
|
If the transformer reports |
Source Code ¶
Source code in src/yohou/base/transformer.py
observe(X)
¶
Observe new data and update internal memory.
Extends the internal memory buffer with new observations, then
calls rewind() to maintain the fixed observation_horizon
window.
Parameters ¶
| Name | Type | Description | Default |
|---|---|---|---|
X
|
DataFrame
|
Input time series with a |
required |
Returns ¶
| Type | Description |
|---|---|
self
|
The transformer with updated internal memory from new observations. |
Raises ¶
| Type | Description |
|---|---|
NotFittedError
|
If the transformer has not been fitted. |
ValueError
|
If |
Source Code ¶
Source code in src/yohou/base/transformer.py
transform(X, **params)
¶
Transform the input time series.
Parameters ¶
| Name | Type | Description | Default |
|---|---|---|---|
X
|
DataFrame
|
Input time series with a |
required |
**params
|
dict
|
Metadata to route to nested estimators. |
{}
|
Returns ¶
| Type | Description |
|---|---|
DataFrame
|
Transformed time series with a |
Source Code ¶
Source code in src/yohou/base/transformer.py
inverse_transform(X_t, X_p=None)
¶
Inverse-transform the data back to the original space.
Parameters ¶
| Name | Type | Description | Default |
|---|---|---|---|
X_t
|
DataFrame
|
Transformed time series to invert. |
required |
X_p
|
DataFrame or None
|
Past observations needed by stateful transformers. |
None
|
Returns ¶
| Type | Description |
|---|---|
DataFrame
|
Data in the original (pre-transform) space. |
Source Code ¶
Source code in src/yohou/base/transformer.py
observe_transform(X, **params)
¶
Transform using pre-existing memory, then observe state.
Performs a stateful transformation by concatenating stored observations with the new input, applying the transformation, and then updating the internal state.
Transforms using pre-existing memory first, then updates state with
observe(X). This is NOT equivalent to observe(X); transform(X),
since the transform uses memory from before the observation.
Parameters ¶
| Name | Type | Description | Default |
|---|---|---|---|
X
|
DataFrame
|
Input time series with a |
required |
**params
|
dict
|
Metadata to route to nested estimators. |
{}
|
Returns ¶
| Type | Description |
|---|---|
DataFrame
|
Transformed time series with a |
Raises ¶
| Type | Description |
|---|---|
NotFittedError
|
If the transformer has not been fitted yet. |
ValueError
|
If |
Source Code ¶
Source code in src/yohou/base/transformer.py
rewind_transform(X, **params)
¶
Transform the input and rewind state (stateless transform).
Applies the transformation to the full input and then rewinds
internal state. Stateful subclasses typically discard the first
observation_horizon rows inside _transform(), so the result
usually has len(X) - observation_horizon rows, but the exact count
depends on the transformer implementation.
Equivalent to calling rewind(X) then transform(X).
Parameters ¶
| Name | Type | Description | Default |
|---|---|---|---|
X
|
DataFrame
|
Input time series with a |
required |
**params
|
dict
|
Metadata to route to nested estimators. |
{}
|
Returns ¶
| Type | Description |
|---|---|
DataFrame
|
Transformed time series with the first |
Raises ¶
| Type | Description |
|---|---|
NotFittedError
|
If the transformer has not been fitted yet. |
Source Code ¶
Source code in src/yohou/base/transformer.py
Tutorials¶
The following example notebooks use this component:
-
How to Create a Custom Transformer
Implement a ScaleTransformer from scratch, validate it with the check generator, and use it in a forecast pipeline.