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. Features values of new/unseen data that fall below or above the fitted range will be mapped to the bounds of the output distribution. Note that this transform is non-linear. It may distort linear correlations between variables measured at the same scale but renders variables measured at different scales more directly comparable.
For example visualizations, refer to Compare QuantileTransformer with other scalers.
Read more in the User Guide.
Added in version 0.19.
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 as a larger number of quantiles does not give a better approximation of the cumulative distribution function estimator.
Marginal distribution for the transformed data. The choices are ‘uniform’ (default) or ‘normal’.
Only applies to sparse matrices. If True, the sparse entries of the matrix are discarded to compute the quantile statistics. If False, these entries are treated as zeros.
Maximum number of samples used to estimate the quantiles for computational efficiency. Note that the subsampling procedure may differ for value-identical sparse and dense matrices. Disable subsampling by setting subsample=None
.
Added in version 1.5: The option None
to disable subsampling was added.
Determines random number generation for subsampling and smoothing noise. Please see subsample
for more details. Pass an int for reproducible results across multiple function calls. See Glossary.
Set to False to perform inplace transformation and avoid a copy (if the input is already a numpy array).
The actual number of quantiles used to discretize the cumulative distribution function.
The values corresponding the quantiles of reference.
Quantiles of references.
Number of features seen during fit.
Added in version 0.24.
n_features_in_
,)
Names of features seen during fit. Defined only when X
has feature names that are all strings.
Added in version 1.0.
See also
quantile_transform
Equivalent function without the estimator API.
PowerTransformer
Perform mapping to a normal distribution using a power transform.
StandardScaler
Perform standardization that is faster, but less robust to outliers.
RobustScaler
Perform robust standardization that removes the influence of outliers but does not put outliers and inliers on the same scale.
Notes
NaNs are treated as missing values: disregarded in fit, and maintained in transform.
Examples
>>> import numpy as np >>> from sklearn.preprocessing import QuantileTransformer >>> rng = np.random.RandomState(0) >>> X = np.sort(rng.normal(loc=0.5, scale=0.25, size=(25, 1)), axis=0) >>> qt = QuantileTransformer(n_quantiles=10, random_state=0) >>> qt.fit_transform(X) array([...])
Compute the quantiles used for transforming.
The data used to scale along the features axis. If a sparse matrix is provided, it will be converted into a sparse csc_matrix
. Additionally, the sparse matrix needs to be nonnegative if ignore_implicit_zeros
is False.
Ignored.
Fitted transformer.
Fit to data, then transform it.
Fits transformer to X
and y
with optional parameters fit_params
and returns a transformed version of X
.
Input samples.
Target values (None for unsupervised transformations).
Additional fit parameters.
Transformed array.
Get output feature names for transformation.
Input features.
If input_features
is None
, then feature_names_in_
is used as feature names in. If feature_names_in_
is not defined, then the following input feature names are generated: ["x0", "x1", ..., "x(n_features_in_ - 1)"]
.
If input_features
is an array-like, then input_features
must match feature_names_in_
if feature_names_in_
is defined.
Same as input features.
Get metadata routing of this object.
Please check User Guide on how the routing mechanism works.
A MetadataRequest
encapsulating routing information.
Get parameters for this estimator.
If True, will return the parameters for this estimator and contained subobjects that are estimators.
Parameter names mapped to their values.
Back-projection to the original space.
The data used to scale along the features axis. If a sparse matrix is provided, it will be converted into a sparse csc_matrix
. Additionally, the sparse matrix needs to be nonnegative if ignore_implicit_zeros
is False.
The projected data.
Set output container.
See Introducing the set_output API for an example on how to use the API.
Configure output of transform
and fit_transform
.
"default"
: Default output format of a transformer
"pandas"
: DataFrame output
"polars"
: Polars output
None
: Transform configuration is unchanged
Added in version 1.4: "polars"
option was added.
Estimator instance.
Set the parameters of this estimator.
The method works on simple estimators as well as on nested objects (such as Pipeline
). The latter have parameters of the form <component>__<parameter>
so that it’s possible to update each component of a nested object.
Estimator parameters.
Estimator instance.
Feature-wise transformation of the data.
The data used to scale along the features axis. If a sparse matrix is provided, it will be converted into a sparse csc_matrix
. Additionally, the sparse matrix needs to be nonnegative if ignore_implicit_zeros
is False.
The projected data.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4