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
| 2668 | |
| 2669 | |
| 2670 | class QuantileTransformer(OneToOneFeatureMixin, TransformerMixin, BaseEstimator): |
| 2671 | """Transform features using quantiles information. |
| 2672 | |
| 2673 | This method transforms the features to follow a uniform or a normal |
| 2674 | distribution. Therefore, for a given feature, this transformation tends |
| 2675 | to spread out the most frequent values. It also reduces the impact of |
| 2676 | (marginal) outliers: this is therefore a robust preprocessing scheme. |
| 2677 | |
| 2678 | The transformation is applied on each feature independently. First an |
| 2679 | estimate of the cumulative distribution function of a feature is |
| 2680 | used to map the original values to a uniform distribution. The obtained |
| 2681 | values are then mapped to the desired output distribution using the |
| 2682 | associated quantile function. Features values of new/unseen data that fall |
| 2683 | below or above the fitted range will be mapped to the bounds of the output |
| 2684 | distribution. Note that this transform is non-linear. It may distort linear |
| 2685 | correlations between variables measured at the same scale but renders |
| 2686 | variables measured at different scales more directly comparable. |
| 2687 | |
| 2688 | For example visualizations, refer to :ref:`Compare QuantileTransformer with |
| 2689 | other scalers <plot_all_scaling_quantile_transformer_section>`. |
| 2690 | |
| 2691 | Read more in the :ref:`User Guide <preprocessing_transformer>`. |
| 2692 | |
| 2693 | .. versionadded:: 0.19 |
| 2694 | |
| 2695 | Parameters |
| 2696 | ---------- |
| 2697 | n_quantiles : int, default=1000 or n_samples |
| 2698 | Number of quantiles to be computed. It corresponds to the number |
| 2699 | of landmarks used to discretize the cumulative distribution function. |
| 2700 | If n_quantiles is larger than the number of samples, n_quantiles is set |
| 2701 | to the number of samples as a larger number of quantiles does not give |
| 2702 | a better approximation of the cumulative distribution function |
| 2703 | estimator. |
| 2704 | |
| 2705 | output_distribution : {'uniform', 'normal'}, default='uniform' |
| 2706 | Marginal distribution for the transformed data. The choices are |
| 2707 | 'uniform' (default) or 'normal'. |
| 2708 | |
| 2709 | ignore_implicit_zeros : bool, default=False |
| 2710 | Only applies to sparse matrices. If True, the sparse entries of the |
| 2711 | matrix are discarded to compute the quantile statistics. If False, |
| 2712 | these entries are treated as zeros. |
| 2713 | |
| 2714 | subsample : int or None, default=10_000 |
| 2715 | Maximum number of samples used to estimate the quantiles for |
| 2716 | computational efficiency. Note that the subsampling procedure may |
| 2717 | differ for value-identical sparse and dense matrices. |
| 2718 | Disable subsampling by setting `subsample=None`. |
| 2719 | |
| 2720 | .. versionadded:: 1.5 |
| 2721 | The option `None` to disable subsampling was added. |
| 2722 | |
| 2723 | random_state : int, RandomState instance or None, default=None |
| 2724 | Determines random number generation for subsampling and smoothing |
| 2725 | noise. |
| 2726 | Please see ``subsample`` for more details. |
| 2727 | Pass an int for reproducible results across multiple function calls. |
searching dependent graphs…