QuantileTransformer¶
yohou.preprocessing.sklearn_wrappers.QuantileTransformer
¶
Bases: SklearnTransformer
Transform features using quantiles information.
This method transforms the features to follow a uniform or a normal distribution. Therefore, for a given feature, this transformation tends to spread out the most frequent values. It also reduces the impact of (marginal) outliers: this is therefore a robust preprocessing scheme.
The transformation is applied on each feature independently. First an estimate of the cumulative distribution function of a feature is used to map the original values to a uniform distribution. The obtained values are then mapped to the desired output distribution using the associated quantile function.
This is a Yohou wrapper that preserves the polars DataFrame structure and "time" column.
Parameters¶
| Name | Type | Description | Default |
|---|---|---|---|
n_quantiles
|
int
|
Number of quantiles to be computed. It corresponds to the number of landmarks used to discretize the cumulative distribution function. If n_quantiles is larger than the number of samples, n_quantiles is set to the number of samples. |
1000 or n_samples
|
output_distribution
|
('uniform', 'normal')
|
Marginal distribution for the transformed data. The choices are 'uniform' (default) or 'normal'. |
'uniform'
|
ignore_implicit_zeros
|
bool
|
Only applies to sparse matrices. If True, the sparse entries of the matrix are discarded to compute the quantile statistics. |
False
|
subsample
|
int
|
Maximum number of samples used to estimate the quantiles for computational efficiency. |
10_000
|
random_state
|
int, RandomState instance or None
|
Determines random number generation for subsampling and smoothing noise. |
None
|
Attributes¶
| Name | Type | Description |
|---|---|---|
instance_ |
QuantileTransformer
|
The fitted sklearn QuantileTransformer instance. |
n_quantiles_ |
int
|
The actual number of quantiles used to discretize the cumulative distribution function. |
quantiles_ |
ndarray of shape (n_quantiles, n_features)
|
The values corresponding to the quantiles of reference. |
references_ |
ndarray of shape (n_quantiles,)
|
Quantiles of references. |
Examples¶
>>> import polars as pl
>>> from datetime import datetime
>>> from yohou.preprocessing import QuantileTransformer
>>> X = pl.DataFrame({
... "time": [datetime(2024, 1, i) for i in range(1, 11)],
... "value": [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 100.0], # 100 is outlier
... })
>>> qt = QuantileTransformer(n_quantiles=10, output_distribution="uniform")
>>> qt.fit(X)
QuantileTransformer(...)
>>> X_transformed = qt.transform(X)
>>> # Outlier impact is reduced
>>> "time" in X_transformed.columns
True
See Also¶
PowerTransformer: Apply a power transform to make data more Gaussian-like.
Source Code¶
Show/Hide source
653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 | |