SimpleTimeImputer¶
yohou.preprocessing.imputation.SimpleTimeImputer
¶
Bases: BaseTransformer
Time series imputation using interpolation or filling methods.
Imputes missing values using time series-aware methods like linear interpolation, forward fill, backward fill, or combinations.
Parameters¶
| Name | Type | Description | Default |
|---|---|---|---|
method
|
(linear, forward, backward, nearest, fill_both)
|
Imputation method: - "linear": Linear interpolation between known values - "forward": Forward fill (last observation carried forward) - "backward": Backward fill (next observation carried backward) - "nearest": Use nearest non-null value - "fill_both": Forward fill then backward fill (handles edges) |
"linear"
|
limit
|
int or None
|
Maximum number of consecutive NaN values to fill. If None, no limit. |
None
|
Attributes¶
| Name | Type | Description |
|---|---|---|
method_ |
str
|
Validated imputation method. |
Examples¶
>>> import polars as pl
>>> from datetime import datetime
>>> import numpy as np
>>> from yohou.preprocessing import SimpleTimeImputer
>>> X = pl.DataFrame({
... "time": [datetime(2020, 1, i) for i in range(1, 8)],
... "value": [1.0, np.nan, np.nan, 4.0, np.nan, 6.0, 7.0],
... })
>>> # Linear interpolation
>>> imputer = SimpleTimeImputer(method="linear")
>>> imputer.fit(X)
SimpleTimeImputer()
>>> X_imputed = imputer.transform(X)
>>> X_imputed["value"].null_count()
0
>>> # Forward fill with limit
>>> imputer = SimpleTimeImputer(method="forward", limit=1)
>>> imputer.fit(X)
SimpleTimeImputer(...)
>>> X_imputed = imputer.transform(X)
>>> "time" in X_imputed.columns
True
See Also¶
SimpleImputer: Simple constant-strategy imputation.SeasonalImputer: Seasonal decomposition-based imputation.
Source Code¶
Show/Hide source
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 | |
Methods¶
fit(X, y=None, **params)
¶
Fit the imputer (validates parameters).
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.
-
How to Preprocess Panel Data
Panel-Data
Automatic panel-aware transformation (StandardScaler, rolling stats, imputation) plus manual per-group workflows with get_group_df and dict_to_panel.