SeasonalImputer¶
yohou.preprocessing.imputation.SeasonalImputer
¶
Bases: BaseTransformer
Seasonal decomposition-based imputation for missing values.
Imputes missing values by leveraging seasonal patterns in the data. Missing values are replaced with the seasonally-adjusted expected value based on the seasonal component estimated from non-missing data.
Parameters¶
| Name | Type | Description | Default |
|---|---|---|---|
period
|
int
|
Seasonal period (e.g., 7 for weekly, 12 for monthly with annual seasonality). Must be >= 2. |
required |
fill_method
|
(seasonal_mean, seasonal_median)
|
Method to compute seasonal values: - "seasonal_mean": Use mean of same-season observations - "seasonal_median": Use median of same-season observations |
"seasonal_mean"
|
Attributes¶
| Name | Type | Description |
|---|---|---|
seasonal_values_ |
dict
|
Dictionary mapping column names to seasonal value arrays of shape (period,). |
Examples¶
>>> import polars as pl
>>> from datetime import datetime
>>> import numpy as np
>>> from yohou.preprocessing import SeasonalImputer
>>> # Weekly data with missing values
>>> X = pl.DataFrame({
... "time": [datetime(2020, 1, i) for i in range(1, 15)],
... "value": [10.0, 20.0, 30.0, 25.0, 15.0, 5.0, 8.0, np.nan, 21.0, 31.0, np.nan, 16.0, 6.0, 9.0],
... })
>>> imputer = SeasonalImputer(period=7)
>>> imputer.fit(X)
SeasonalImputer(period=7)
>>> X_imputed = imputer.transform(X)
>>> X_imputed["value"].null_count()
0
See Also¶
SimpleTimeImputer: Interpolation-based imputation.SimpleImputer: Simple constant-strategy imputation.
Source Code¶
Show/Hide source
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 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 | |
Methods¶
fit(X, y=None, **params)
¶
Fit the imputer by computing seasonal values.
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. |
Source Code¶
Show/Hide source
get_feature_names_out(input_features=None)
¶
Get output feature names for transformation.
Parameters¶
| Name | Type | Description | Default |
|---|---|---|---|
input_features
|
list of str or None
|
Column names of the input features. If |
None
|
Returns¶
| Type | Description |
|---|---|
list of str
|
Output feature names after transformation. |
Source Code¶
Show/Hide source
Tutorials¶
The following example notebooks use this component:
-
How to Handle Missing Data
Data-Features
Compare SimpleTimeImputer, SeasonalImputer, SimpleImputer, and TransformedSpaceKNNImputer on synthetic block and scattered gaps in monthly tourism data.
-
How to Clean Time Series Data
Data-Features
End-to-end data cleaning pipeline combining SimpleTimeImputer and SeasonalImputer for missing values with OutlierThresholdHandler for anomaly clipping.