MaxAbsScaler¶
yohou.preprocessing.MaxAbsScaler
¶
Bases: SklearnScaler
Scale each feature by its maximum absolute value.
This estimator scales and translates each feature individually such that the maximal absolute value of each feature in the training set will be 1.0. It does not shift/center the data, and thus does not destroy any sparsity.
MaxAbsScaler doesn't reduce the effect of outliers; it only linearly
scales them down.
This is a Yohou wrapper that preserves the polars DataFrame structure and "time" column.
Parameters ¶
| Name | Type | Description | Default |
|---|---|---|---|
copy
|
bool
|
If True, a copy of the data is made before transforming. Pass False only if in-place modification of the input is acceptable. |
True
|
clip
|
bool
|
Set to True to clip transformed values of held-out data to [-1, 1]. |
False
|
Attributes ¶
| Name | Type | Description |
|---|---|---|
instance_ |
MaxAbsScaler
|
The fitted sklearn MaxAbsScaler instance. |
scale_ |
ndarray of shape (n_features,)
|
Per feature relative scaling of the data. |
max_abs_ |
ndarray of shape (n_features,)
|
Per feature maximum absolute value. |
Examples ¶
>>> import polars as pl
>>> from datetime import datetime
>>> from yohou.preprocessing import MaxAbsScaler
>>> X = pl.DataFrame({
... "time": [datetime(2024, 1, i) for i in range(1, 6)],
... "value": [-50.0, -25.0, 0.0, 25.0, 50.0],
... })
>>> scaler = MaxAbsScaler()
>>> scaler.fit(X)
MaxAbsScaler(...)
>>> X_scaled = scaler.transform(X)
>>> # Values scaled to [-1, 1] range
>>> X_scaled["value"].max()
1.0
>>> X_scaled["value"].min()
-1.0
See Also ¶
MinMaxScaler: Scale features to a given range.StandardScaler: Standardize features by removing mean and scaling to unit variance.
Source Code ¶
Source code in src/yohou/preprocessing/sklearn_wrappers.py
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 | |