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.


Return feature names for output features
String names for input features if available. By default, “x0”, “x1”, … “xn_features” is used.


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.


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.


Transform data to polynomial features
The data to transform, row by row.
Prefer CSR over CSC for sparse input (for speed), but CSC is required if the degree is 4 or higher. If the degree is less than 4 and the input format is CSC, it will be converted to CSR, have its polynomial features generated, then converted back to CSC.
If the degree is 2 or 3, the method described in “Leveraging Sparsity to Speed Up Polynomial Feature Expansions of CSR Matrices Using K-Simplex Numbers” by Andrew Nystrom and John Hughes is used, which is much faster than the method used on CSC input. For this reason, a CSC input will be converted to CSR, and the output will be converted back to CSC prior to being returned, hence the preference of CSR.
The matrix of features, where NP is the number of polynomial features generated from the combination of inputs. If a sparse matrix is provided, it will be converted into a sparse csr_matrix.


Apply a power transform featurewise to make data more Gaussian-like.
Power transforms are a family of parametric, monotonic transformations that are applied to make data more Gaussian-like. This is useful for modeling issues related to heteroscedasticity (non-constant variance), or other situations where normality is desired.
Currently, PowerTransformer supports the Box-Cox transform and the Yeo-Johnson transform. The optimal parameter for stabilizing variance and minimizing skewness is estimated through maximum likelihood.
Box-Cox requires input data to be strictly positive, while Yeo-Johnson supports both positive or negative data.
By default, zero-mean, unit-variance normalization is applied to the transformed data.
Read more in the User Guide.
New in version 0.20.
The power transform method. Available methods are:
Set to True to apply zero-mean, unit-variance normalization to the transformed output.
Set to False to perform inplace computation during transformation.
The parameters of the power transformation for the selected features.
See also
Equivalent function without the estimator API.
Maps data to a standard normal distribution with the parameter output_distribution='normal'.
NaNs are treated as missing values: disregarded in fit, and maintained in transform.
For a comparison of the different scalers, transformers, and normalizers, see examples/preprocessing/plot_all_scaling.py.
I.K. Yeo and R.A. Johnson, “A new family of power transformations to improve normality or symmetry.” Biometrika, 87(4), pp.954-959, (2000).
G.E.P. Box and D.R. Cox, “An Analysis of Transformations”, Journal of the Royal Statistical Society B, 26, 211-252 (1964).
fit(X[, y])
Estimate the optimal parameter lambda for each feature.
fit_transform(X[, y])
Fit to data, then transform it.
get_params([deep])
Get parameters for this estimator.
inverse_transform(X)
Apply the inverse power transformation using the fitted lambdas.
set_params(**params)
Set the parameters of this estimator.
transform(X)
Apply the power transform to each feature using the fitted lambdas.
Estimate the optimal parameter lambda for each feature.
The optimal lambda parameter for minimizing skewness is estimated on each feature independently using maximum likelihood.
The data used to estimate the optimal transformation parameters.
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 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.
Apply the inverse power transformation using the fitted lambdas.
The inverse of the Box-Cox transformation is given by:
The inverse of the Yeo-Johnson transformation is given by:
The transformed data.
The original data.
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.
Apply the power transform to each feature using the fitted lambdas.
The data to be transformed using a power transformation.
The transformed data.


Apply a power transform featurewise to make data more Gaussian-like.
Power transforms are a family of parametric, monotonic transformations that are applied to make data more Gaussian-like. This is useful for modeling issues related to heteroscedasticity (non-constant variance), or other situations where normality is desired.
Currently, PowerTransformer supports the Box-Cox transform and the Yeo-Johnson transform. The optimal parameter for stabilizing variance and minimizing skewness is estimated through maximum likelihood.
Box-Cox requires input data to be strictly positive, while Yeo-Johnson supports both positive or negative data.
By default, zero-mean, unit-variance normalization is applied to the transformed data.
Read more in the User Guide.
New in version 0.20.
The power transform method. Available methods are:
Set to True to apply zero-mean, unit-variance normalization to the transformed output.
Set to False to perform inplace computation during transformation.
The parameters of the power transformation for the selected features.
See also
Equivalent function without the estimator API.
Maps data to a standard normal distribution with the parameter output_distribution='normal'.
NaNs are treated as missing values: disregarded in fit, and maintained in transform.
For a comparison of the different scalers, transformers, and normalizers, see examples/preprocessing/plot_all_scaling.py.
I.K. Yeo and R.A. Johnson, “A new family of power transformations to improve normality or symmetry.” Biometrika, 87(4), pp.954-959, (2000).
G.E.P. Box and D.R. Cox, “An Analysis of Transformations”, Journal of the Royal Statistical Society B, 26, 211-252 (1964).
fit(X[, y])
Estimate the optimal parameter lambda for each feature.
fit_transform(X[, y])
Fit to data, then transform it.
get_params([deep])
Get parameters for this estimator.
inverse_transform(X)
Apply the inverse power transformation using the fitted lambdas.
set_params(**params)
Set the parameters of this estimator.
transform(X)
Apply the power transform to each feature using the fitted lambdas.
Estimate the optimal parameter lambda for each feature.
The optimal lambda parameter for minimizing skewness is estimated on each feature independently using maximum likelihood.
The data used to estimate the optimal transformation parameters.
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 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.
Apply the inverse power transformation using the fitted lambdas.
The inverse of the Box-Cox transformation is given by:
The inverse of the Yeo-Johnson transformation is given by:
The transformed data.
The original data.
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.
Apply the power transform to each feature using the fitted lambdas.
The data to be transformed using a power transformation.
The transformed data.
Map data to a normal distribution
Compare the effect of different scalers on data with outliers


Estimate the optimal parameter lambda for each feature.
The optimal lambda parameter for minimizing skewness is estimated on each feature independently using maximum likelihood.
The data used to estimate the optimal transformation parameters.
Ignored.
Fitted transformer.


Apply the inverse power transformation using the fitted lambdas.
The inverse of the Box-Cox transformation is given by:
The inverse of the Yeo-Johnson transformation is given by:
The transformed data.
The original data.


Apply the power transform to each feature using the fitted lambdas.
The data to be transformed using a power transformation.
The transformed data.


Power transforms are a family of parametric, monotonic transformations that are applied to make data more Gaussian-like. This is useful for modeling issues related to heteroscedasticity (non-constant variance), or other situations where normality is desired.
Currently, power_transform supports the Box-Cox transform and the Yeo-Johnson transform. The optimal parameter for stabilizing variance and minimizing skewness is estimated through maximum likelihood.
Box-Cox requires input data to be strictly positive, while Yeo-Johnson supports both positive or negative data.
By default, zero-mean, unit-variance normalization is applied to the transformed data.
Read more in the User Guide.
The data to be transformed using a power transformation.
The power transform method. Available methods are:
Changed in version 0.23: The default value of the method parameter changed from ‘box-cox’ to ‘yeo-johnson’ in 0.23.
Set to True to apply zero-mean, unit-variance normalization to the transformed output.
Set to False to perform inplace computation during transformation.
The transformed data.
See also
Equivalent transformation with the Transformer API (e.g. as part of a preprocessing Pipeline).
Maps data to a standard normal distribution with the parameter output_distribution='normal'.
NaNs are treated as missing values: disregarded in fit, and maintained in transform.
For a comparison of the different scalers, transformers, and normalizers, see examples/preprocessing/plot_all_scaling.py.
I.K. Yeo and R.A. Johnson, “A new family of power transformations to improve normality or symmetry.” Biometrika, 87(4), pp.954-959, (2000).
G.E.P. Box and D.R. Cox, “An Analysis of Transformations”, Journal of the Royal Statistical Society B, 26, 211-252 (1964).
Warning
Risk of data leak. Do not use power_transform unless you know what you are doing. A common mistake is to apply it to the entire data before splitting into training and test sets. This will bias the model evaluation because information would have leaked from the test set to the training set. In general, we recommend using PowerTransformer within a Pipeline in order to prevent most risks of data leaking, e.g.: pipe = make_pipeline(PowerTransformer(),
LogisticRegression()).


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.
Read more in the User Guide.
New 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.
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.
See also
Equivalent function without the estimator API.
Perform mapping to a normal distribution using a power transform.
Perform standardization that is faster, but less robust to outliers.
Perform robust standardization that removes the influence of outliers but does not put outliers and inliers on the same scale.
NaNs are treated as missing values: disregarded in fit, and maintained in transform.
For a comparison of the different scalers, transformers, and normalizers, see examples/preprocessing/plot_all_scaling.py.
fit(X[, y])
Compute the quantiles used for transforming.
fit_transform(X[, y])
Fit to data, then transform it.
get_params([deep])
Get parameters for this estimator.
inverse_transform(X)
Back-projection to the original space.
set_params(**params)
Set the parameters of this estimator.
transform(X)
Feature-wise transformation of the data.
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 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 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.


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.
Read more in the User Guide.
New 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.
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.
See also
Equivalent function without the estimator API.
Perform mapping to a normal distribution using a power transform.
Perform standardization that is faster, but less robust to outliers.
Perform robust standardization that removes the influence of outliers but does not put outliers and inliers on the same scale.
NaNs are treated as missing values: disregarded in fit, and maintained in transform.
For a comparison of the different scalers, transformers, and normalizers, see examples/preprocessing/plot_all_scaling.py.
fit(X[, y])
Compute the quantiles used for transforming.
fit_transform(X[, y])
Fit to data, then transform it.
get_params([deep])
Get parameters for this estimator.
inverse_transform(X)
Back-projection to the original space.
set_params(**params)
Set the parameters of this estimator.
transform(X)
Feature-wise transformation of the data.
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 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 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.
Partial Dependence and Individual Conditional Expectation Plots
Effect of transforming the targets in regression model
Map data to a normal distribution
Compare the effect of different scalers on data with outliers


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.


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.


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.


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.
Read more in the User Guide.
The data to transform.
Axis used to compute the means and standard deviations along. If 0, transform each feature, otherwise (if 1) transform each sample.
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.
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). If True, a copy of X is transformed, leaving the original X unchanged
The default value of copy changed from False to True in 0.23.
The transformed data.
See also
Performs quantile-based scaling using the Transformer API (e.g. as part of a preprocessing Pipeline).
Maps data to a normal distribution using a power transformation.
Performs standardization that is faster, but less robust to outliers.
Performs robust standardization that removes the influence of outliers but does not put outliers and inliers on the same scale.
NaNs are treated as missing values: disregarded in fit, and maintained in transform.
Warning
Risk of data leak
Do not use quantile_transform unless you know what you are doing. A common mistake is to apply it to the entire data before splitting into training and test sets. This will bias the model evaluation because information would have leaked from the test set to the training set. In general, we recommend using QuantileTransformer within a Pipeline in order to prevent most risks of data leaking:pipe = make_pipeline(QuantileTransformer(),
LogisticRegression()).
For a comparison of the different scalers, transformers, and normalizers, see examples/preprocessing/plot_all_scaling.py.


Scale features using statistics that are robust to outliers.
This Scaler removes the median and scales the data according to the quantile range (defaults to IQR: Interquartile Range). The IQR is the range between the 1st quartile (25th quantile) and the 3rd quartile (75th quantile).
Centering and scaling happen independently on each feature by computing the relevant statistics on the samples in the training set. Median and interquartile range are then stored to be used on later data using the transform method.
Standardization of a dataset is a common requirement for many machine learning estimators. Typically this is done by removing the mean and scaling to unit variance. However, outliers can often influence the sample mean / variance in a negative way. In such cases, the median and the interquartile range often give better results.
New in version 0.17.
Read more in the User Guide.
If True, center the data before scaling. This will cause transform to raise an exception when attempted on sparse matrices, because centering them entails building a dense matrix which in common use cases is likely to be too large to fit in memory.
If True, scale the data to interquartile range.
Quantile range used to calculate scale_.
New in version 0.18.
If False, try to avoid a copy and do inplace scaling instead. This is not guaranteed to always work inplace; e.g. if the data is not a NumPy array or scipy.sparse CSR matrix, a copy may still be returned.
If True, scale data so that normally distributed features have a variance of 1. In general, if the difference between the x-values of q_max and q_min for a standard normal distribution is greater than 1, the dataset will be scaled down. If less than 1, the dataset will be scaled up.
New in version 0.24.
The median value for each feature in the training set.
The (scaled) interquartile range for each feature in the training set.
New in version 0.17: scale_ attribute.
See also
Equivalent function without the estimator API.
Further removes the linear correlation across features with ‘whiten=True’.
For a comparison of the different scalers, transformers, and normalizers, see examples/preprocessing/plot_all_scaling.py.
https://en.wikipedia.org/wiki/Median https://en.wikipedia.org/wiki/Interquartile_range
fit(X[, y])
Compute the median and quantiles to be used for scaling.
fit_transform(X[, y])
Fit to data, then transform it.
get_params([deep])
Get parameters for this estimator.
inverse_transform(X)
Scale back the data to the original representation
set_params(**params)
Set the parameters of this estimator.
transform(X)
Center and scale the data.
Compute the median and quantiles to be used for scaling.
The data used to compute the median and quantiles used for later scaling along the features axis.
Ignored.
Fitted scaler.
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 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.
Scale back the data to the original representation
The rescaled data to be transformed back.
Transformed array.
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.
Center and scale the data.
The data used to scale along the specified axis.
Transformed array.


Scale features using statistics that are robust to outliers.
This Scaler removes the median and scales the data according to the quantile range (defaults to IQR: Interquartile Range). The IQR is the range between the 1st quartile (25th quantile) and the 3rd quartile (75th quantile).
Centering and scaling happen independently on each feature by computing the relevant statistics on the samples in the training set. Median and interquartile range are then stored to be used on later data using the transform method.
Standardization of a dataset is a common requirement for many machine learning estimators. Typically this is done by removing the mean and scaling to unit variance. However, outliers can often influence the sample mean / variance in a negative way. In such cases, the median and the interquartile range often give better results.
New in version 0.17.
Read more in the User Guide.
If True, center the data before scaling. This will cause transform to raise an exception when attempted on sparse matrices, because centering them entails building a dense matrix which in common use cases is likely to be too large to fit in memory.
If True, scale the data to interquartile range.
Quantile range used to calculate scale_.
New in version 0.18.
If False, try to avoid a copy and do inplace scaling instead. This is not guaranteed to always work inplace; e.g. if the data is not a NumPy array or scipy.sparse CSR matrix, a copy may still be returned.
If True, scale data so that normally distributed features have a variance of 1. In general, if the difference between the x-values of q_max and q_min for a standard normal distribution is greater than 1, the dataset will be scaled down. If less than 1, the dataset will be scaled up.
New in version 0.24.
The median value for each feature in the training set.
The (scaled) interquartile range for each feature in the training set.
New in version 0.17: scale_ attribute.
See also
Equivalent function without the estimator API.
Further removes the linear correlation across features with ‘whiten=True’.
For a comparison of the different scalers, transformers, and normalizers, see examples/preprocessing/plot_all_scaling.py.
https://en.wikipedia.org/wiki/Median https://en.wikipedia.org/wiki/Interquartile_range
fit(X[, y])
Compute the median and quantiles to be used for scaling.
fit_transform(X[, y])
Fit to data, then transform it.
get_params([deep])
Get parameters for this estimator.
inverse_transform(X)
Scale back the data to the original representation
set_params(**params)
Set the parameters of this estimator.
transform(X)
Center and scale the data.
Compute the median and quantiles to be used for scaling.
The data used to compute the median and quantiles used for later scaling along the features axis.
Ignored.
Fitted scaler.
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 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.
Scale back the data to the original representation
The rescaled data to be transformed back.
Transformed array.
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.
Center and scale the data.
The data used to scale along the specified axis.
Transformed array.
Compare the effect of different scalers on data with outliers


Compute the median and quantiles to be used for scaling.
The data used to compute the median and quantiles used for later scaling along the features axis.
Ignored.
Fitted scaler.


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 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.


Scale back the data to the original representation
The rescaled data to be transformed back.
Transformed array.


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.


Center and scale the data.
The data used to scale along the specified axis.
Transformed array.


Standardize a dataset along any axis
Center to the median and component wise scale according to the interquartile range.
Read more in the User Guide.
The data to center and scale.
axis used to compute the medians and IQR along. If 0, independently scale each feature, otherwise (if 1) scale each sample.
If True, center the data before scaling.
If True, scale the data to unit variance (or equivalently, unit standard deviation).
default=(25.0, 75.0), == (1st quantile, 3rd quantile), == IQR Quantile range used to calculate scale_.
New in version 0.18.
set to False to perform inplace row normalization and avoid a copy (if the input is already a numpy array or a scipy.sparse CSR matrix and if axis is 1).
If True, scale data so that normally distributed features have a variance of 1. In general, if the difference between the x-values of q_max and q_min for a standard normal distribution is greater than 1, the dataset will be scaled down. If less than 1, the dataset will be scaled up.
New in version 0.24.
The transformed data.
See also
Performs centering and scaling using the Transformer API (e.g. as part of a preprocessing Pipeline).
This implementation will refuse to center scipy.sparse matrices since it would make them non-sparse and would potentially crash the program with memory exhaustion problems.
Instead the caller is expected to either set explicitly with_centering=False (in that case, only variance scaling will be performed on the features of the CSR matrix) or to call X.toarray() if he/she expects the materialized dense array to fit in memory.
To avoid memory copy the caller should pass a CSR matrix.
For a comparison of the different scalers, transformers, and normalizers, see examples/preprocessing/plot_all_scaling.py.
Warning
Risk of data leak
Do not use robust_scale unless you know what you are doing. A common mistake is to apply it to the entire data before splitting into training and test sets. This will bias the model evaluation because information would have leaked from the test set to the training set. In general, we recommend using RobustScaler within a Pipeline in order to prevent most risks of data leaking: pipe = make_pipeline(RobustScaler(), LogisticRegression()).


Standardize a dataset along any axis.
Center to the mean and component wise scale to unit variance.
Read more in the User Guide.
The data to center and scale.
axis used to compute the means and standard deviations along. If 0, independently standardize each feature, otherwise (if 1) standardize each sample.
If True, center the data before scaling.
If True, scale the data to unit variance (or equivalently, unit standard deviation).
set to False to perform inplace row normalization and avoid a copy (if the input is already a numpy array or a scipy.sparse CSC matrix and if axis is 1).
The transformed data.
See also
Performs scaling to unit variance using the Transformer API (e.g. as part of a preprocessing Pipeline).
This implementation will refuse to center scipy.sparse matrices since it would make them non-sparse and would potentially crash the program with memory exhaustion problems.
Instead the caller is expected to either set explicitly with_mean=False (in that case, only variance scaling will be performed on the features of the CSC matrix) or to call X.toarray() if he/she expects the materialized dense array to fit in memory.
To avoid memory copy the caller should pass a CSC matrix.
NaNs are treated as missing values: disregarded to compute the statistics, and maintained during the data transformation.
We use a biased estimator for the standard deviation, equivalent to numpy.std(x, ddof=0). Note that the choice of ddof is unlikely to affect model performance.
For a comparison of the different scalers, transformers, and normalizers, see examples/preprocessing/plot_all_scaling.py.
Warning
Risk of data leak
Do not use scale unless you know what you are doing. A common mistake is to apply it to the entire data before splitting into training and test sets. This will bias the model evaluation because information would have leaked from the test set to the training set. In general, we recommend using StandardScaler within a Pipeline in order to prevent most risks of data leaking: pipe = make_pipeline(StandardScaler(), LogisticRegression()).


Standardize features by removing the mean and scaling to unit variance
The standard score of a sample x is calculated as:
z = (x - u) / s
where u is the mean of the training samples or zero if with_mean=False, and s is the standard deviation of the training samples or one if with_std=False.
Centering and scaling happen independently on each feature by computing the relevant statistics on the samples in the training set. Mean and standard deviation are then stored to be used on later data using transform.
Standardization of a dataset is a common requirement for many machine learning estimators: they might behave badly if the individual features do not more or less look like standard normally distributed data (e.g. Gaussian with 0 mean and unit variance).
For instance many elements used in the objective function of a learning algorithm (such as the RBF kernel of Support Vector Machines or the L1 and L2 regularizers of linear models) assume that all features are centered around 0 and have variance in the same order. If a feature has a variance that is orders of magnitude larger that others, it might dominate the objective function and make the estimator unable to learn from other features correctly as expected.
This scaler can also be applied to sparse CSR or CSC matrices by passing with_mean=False to avoid breaking the sparsity structure of the data.
Read more in the User Guide.
If False, try to avoid a copy and do inplace scaling instead. This is not guaranteed to always work inplace; e.g. if the data is not a NumPy array or scipy.sparse CSR matrix, a copy may still be returned.
If True, center the data before scaling. This does not work (and will raise an exception) when attempted on sparse matrices, because centering them entails building a dense matrix which in common use cases is likely to be too large to fit in memory.
If True, scale the data to unit variance (or equivalently, unit standard deviation).
Per feature relative scaling of the data to achieve zero mean and unit variance. Generally this is calculated using np.sqrt(var_). If a variance is zero, we can’t achieve unit variance, and the data is left as-is, giving a scaling factor of 1. scale_ is equal to None when with_std=False.
New in version 0.17: scale_
The mean value for each feature in the training set. Equal to None when with_mean=False.
The variance for each feature in the training set. Used to compute scale_. Equal to None when with_std=False.
The number of samples processed by the estimator for each feature. If there are no missing samples, the n_samples_seen will be an integer, otherwise it will be an array of dtype int. If sample_weights are used it will be a float (if no missing data) or an array of dtype float that sums the weights seen so far. Will be reset on new calls to fit, but increments across partial_fit calls.
See also
Equivalent function without the estimator API.
Further removes the linear correlation across features with ‘whiten=True’.
NaNs are treated as missing values: disregarded in fit, and maintained in transform.
We use a biased estimator for the standard deviation, equivalent to numpy.std(x, ddof=0). Note that the choice of ddof is unlikely to affect model performance.
For a comparison of the different scalers, transformers, and normalizers, see examples/preprocessing/plot_all_scaling.py.
fit(X[, y, sample_weight])
Compute the mean and std to be used for later scaling.
fit_transform(X[, y])
Fit to data, then transform it.
get_params([deep])
Get parameters for this estimator.
inverse_transform(X[, copy])
Scale back the data to the original representation
partial_fit(X[, y, sample_weight])
Online computation of mean and std on X for later scaling.
set_params(**params)
Set the parameters of this estimator.
transform(X[, copy])
Perform standardization by centering and scaling
Compute the mean and std to be used for later scaling.
The data used to compute the mean and standard deviation used for later scaling along the features axis.
Ignored.
Individual weights for each sample.
New in version 0.24: parameter sample_weight support to StandardScaler.
Fitted scaler.
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 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.
Scale back the data to the original representation
The data used to scale along the features axis.
Copy the input X or not.
Transformed array.
Online computation of mean and std on X for later scaling.
All of X is processed as a single batch. This is intended for cases when fit is not feasible due to very large number of n_samples or because X is read from a continuous stream.
The algorithm for incremental mean and std is given in Equation 1.5a,b in Chan, Tony F., Gene H. Golub, and Randall J. LeVeque. “Algorithms for computing the sample variance: Analysis and recommendations.” The American Statistician 37.3 (1983): 242-247:
The data used to compute the mean and standard deviation used for later scaling along the features axis.
Ignored.
Individual weights for each sample.
New in version 0.24: parameter sample_weight support to StandardScaler.
Fitted scaler.
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.
Perform standardization by centering and scaling
The data used to scale along the features axis.
Copy the input X or not.
Transformed array.


Standardize features by removing the mean and scaling to unit variance
The standard score of a sample x is calculated as:
z = (x - u) / s
where u is the mean of the training samples or zero if with_mean=False, and s is the standard deviation of the training samples or one if with_std=False.
Centering and scaling happen independently on each feature by computing the relevant statistics on the samples in the training set. Mean and standard deviation are then stored to be used on later data using transform.
Standardization of a dataset is a common requirement for many machine learning estimators: they might behave badly if the individual features do not more or less look like standard normally distributed data (e.g. Gaussian with 0 mean and unit variance).
For instance many elements used in the objective function of a learning algorithm (such as the RBF kernel of Support Vector Machines or the L1 and L2 regularizers of linear models) assume that all features are centered around 0 and have variance in the same order. If a feature has a variance that is orders of magnitude larger that others, it might dominate the objective function and make the estimator unable to learn from other features correctly as expected.
This scaler can also be applied to sparse CSR or CSC matrices by passing with_mean=False to avoid breaking the sparsity structure of the data.
Read more in the User Guide.
If False, try to avoid a copy and do inplace scaling instead. This is not guaranteed to always work inplace; e.g. if the data is not a NumPy array or scipy.sparse CSR matrix, a copy may still be returned.
If True, center the data before scaling. This does not work (and will raise an exception) when attempted on sparse matrices, because centering them entails building a dense matrix which in common use cases is likely to be too large to fit in memory.
If True, scale the data to unit variance (or equivalently, unit standard deviation).
Per feature relative scaling of the data to achieve zero mean and unit variance. Generally this is calculated using np.sqrt(var_). If a variance is zero, we can’t achieve unit variance, and the data is left as-is, giving a scaling factor of 1. scale_ is equal to None when with_std=False.
New in version 0.17: scale_
The mean value for each feature in the training set. Equal to None when with_mean=False.
The variance for each feature in the training set. Used to compute scale_. Equal to None when with_std=False.
The number of samples processed by the estimator for each feature. If there are no missing samples, the n_samples_seen will be an integer, otherwise it will be an array of dtype int. If sample_weights are used it will be a float (if no missing data) or an array of dtype float that sums the weights seen so far. Will be reset on new calls to fit, but increments across partial_fit calls.
See also
Equivalent function without the estimator API.
Further removes the linear correlation across features with ‘whiten=True’.
NaNs are treated as missing values: disregarded in fit, and maintained in transform.
We use a biased estimator for the standard deviation, equivalent to numpy.std(x, ddof=0). Note that the choice of ddof is unlikely to affect model performance.
For a comparison of the different scalers, transformers, and normalizers, see examples/preprocessing/plot_all_scaling.py.
fit(X[, y, sample_weight])
Compute the mean and std to be used for later scaling.
fit_transform(X[, y])
Fit to data, then transform it.
get_params([deep])
Get parameters for this estimator.
inverse_transform(X[, copy])
Scale back the data to the original representation
partial_fit(X[, y, sample_weight])
Online computation of mean and std on X for later scaling.
set_params(**params)
Set the parameters of this estimator.
transform(X[, copy])
Perform standardization by centering and scaling
Compute the mean and std to be used for later scaling.
The data used to compute the mean and standard deviation used for later scaling along the features axis.
Ignored.
Individual weights for each sample.
New in version 0.24: parameter sample_weight support to StandardScaler.
Fitted scaler.
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 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.
Scale back the data to the original representation
The data used to scale along the features axis.
Copy the input X or not.
Transformed array.
Online computation of mean and std on X for later scaling.
All of X is processed as a single batch. This is intended for cases when fit is not feasible due to very large number of n_samples or because X is read from a continuous stream.
The algorithm for incremental mean and std is given in Equation 1.5a,b in Chan, Tony F., Gene H. Golub, and Randall J. LeVeque. “Algorithms for computing the sample variance: Analysis and recommendations.” The American Statistician 37.3 (1983): 242-247:
The data used to compute the mean and standard deviation used for later scaling along the features axis.
Ignored.
Individual weights for each sample.
New in version 0.24: parameter sample_weight support to StandardScaler.
Fitted scaler.
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.
Perform standardization by centering and scaling
The data used to scale along the features axis.
Copy the input X or not.
Transformed array.
Release Highlights for scikit-learn 0.23
Release Highlights for scikit-learn 0.22
Classifier comparison
Demo of DBSCAN clustering algorithm
Comparing different hierarchical linkage methods on toy datasets
A demo of K-Means clustering on the handwritten digits data
Comparing different clustering algorithms on toy datasets
Principal Component Regression vs Partial Least Squares Regression
Factor Analysis (with rotation) to visualize patterns
Combine predictors using stacking
Prediction Latency
MNIST classification using multinomial logistic + L1
L1 Penalty and Sparsity in Logistic Regression
Poisson regression and non-normal loss
Tweedie regression on insurance claims
Common pitfalls in interpretation of coefficients of linear models
Visualizations with Display Objects
Advanced Plotting With Partial Dependence
Detection error tradeoff (DET) curve
Comparing Nearest Neighbors with and without Neighborhood Components Analysis
Dimensionality Reduction with Neighborhood Components Analysis
Varying regularization in Multi-layer Perceptron
Column Transformer with Mixed Types
Importance of Feature Scaling
Feature discretization
Compare the effect of different scalers on data with outliers
SVM-Anova: SVM with univariate feature selection
RBF SVM parameters


Compute the mean and std to be used for later scaling.
The data used to compute the mean and standard deviation used for later scaling along the features axis.
Ignored.
Individual weights for each sample.
New in version 0.24: parameter sample_weight support to StandardScaler.
Fitted scaler.


Scale back the data to the original representation
The data used to scale along the features axis.
Copy the input X or not.
Transformed array.


Online computation of mean and std on X for later scaling.
All of X is processed as a single batch. This is intended for cases when fit is not feasible due to very large number of n_samples or because X is read from a continuous stream.
The algorithm for incremental mean and std is given in Equation 1.5a,b in Chan, Tony F., Gene H. Golub, and Randall J. LeVeque. “Algorithms for computing the sample variance: Analysis and recommendations.” The American Statistician 37.3 (1983): 242-247:
The data used to compute the mean and standard deviation used for later scaling along the features axis.
Ignored.
Individual weights for each sample.
New in version 0.24: parameter sample_weight support to StandardScaler.
Fitted scaler.


Perform standardization by centering and scaling
The data used to scale along the features axis.
Copy the input X or not.
Transformed array.


Reduce dimensionality through Gaussian random projection.
The components of the random matrix are drawn from N(0, 1 / n_components).
Read more in the User Guide.
New in version 0.13.
Dimensionality of the target projection space.
n_components can be automatically adjusted according to the number of samples in the dataset and the bound given by the Johnson-Lindenstrauss lemma. In that case the quality of the embedding is controlled by the eps parameter.
It should be noted that Johnson-Lindenstrauss lemma can yield very conservative estimated of the required number of components as it makes no assumption on the structure of the dataset.
Parameter to control the quality of the embedding according to the Johnson-Lindenstrauss lemma when n_components is set to ‘auto’. The value should be strictly positive.
Smaller values lead to better embedding and higher number of dimensions (n_components) in the target projection space.
Controls the pseudo random number generator used to generate the projection matrix at fit time. Pass an int for reproducible output across multiple function calls. See Glossary.
Concrete number of components computed when n_components=”auto”.
Random matrix used for the projection.
See also
fit(X[, y])
Generate a sparse random projection matrix.
fit_transform(X[, y])
Fit to data, then transform it.
get_params([deep])
Get parameters for this estimator.
set_params(**params)
Set the parameters of this estimator.
transform(X)
Project the data by using matrix product with the random matrix
Generate a sparse random projection matrix.
Training set: only the shape is used to find optimal random matrix dimensions based on the theory referenced in the afore mentioned papers.
Ignored
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 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.
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.
Project the data by using matrix product with the random matrix
The input data to project into a smaller dimensional space.
Projected array.


Generate a sparse random projection matrix.
Training set: only the shape is used to find optimal random matrix dimensions based on the theory referenced in the afore mentioned papers.
Ignored


Project the data by using matrix product with the random matrix
The input data to project into a smaller dimensional space.
Projected array.


Find a ‘safe’ number of components to randomly project to.
The distortion introduced by a random projection p only changes the distance between two points by a factor (1 +- eps) in an euclidean space with good probability. The projection p is an eps-embedding as defined by:
(1 - eps) ||u - v||^2 < ||p(u) - p(v)||^2 < (1 + eps) ||u - v||^2
Where u and v are any rows taken from a dataset of shape (n_samples, n_features), eps is in ]0, 1[ and p is a projection by a random Gaussian N(0, 1) matrix of shape (n_components, n_features) (or a sparse Achlioptas matrix).
The minimum number of components to guarantee the eps-embedding is given by:
n_components >= 4 log(n_samples) / (eps^2 / 2 - eps^3 / 3)
Note that the number of dimensions is independent of the original number of features but instead depends on the size of the dataset: the larger the dataset, the higher is the minimal dimensionality of an eps-embedding.
Read more in the User Guide.
Number of samples that should be a integer greater than 0. If an array is given, it will compute a safe number of components array-wise.
Maximum distortion rate in the range (0,1 ) as defined by the Johnson-Lindenstrauss lemma. If an array is given, it will compute a safe number of components array-wise.
The minimal number of components to guarantee with good probability an eps-embedding with n_samples.
https://en.wikipedia.org/wiki/Johnson%E2%80%93Lindenstrauss_lemma
Sanjoy Dasgupta and Anupam Gupta, 1999, “An elementary proof of the Johnson-Lindenstrauss Lemma.” http://citeseer.ist.psu.edu/viewdoc/summary?doi=10.1.1.45.3654


Reduce dimensionality through sparse random projection.
Sparse random matrix is an alternative to dense random projection matrix that guarantees similar embedding quality while being much more memory efficient and allowing faster computation of the projected data.
If we note s = 1 / density the components of the random matrix are drawn from:
Read more in the User Guide.
New in version 0.13.
Dimensionality of the target projection space.
n_components can be automatically adjusted according to the number of samples in the dataset and the bound given by the Johnson-Lindenstrauss lemma. In that case the quality of the embedding is controlled by the eps parameter.
It should be noted that Johnson-Lindenstrauss lemma can yield very conservative estimated of the required number of components as it makes no assumption on the structure of the dataset.
Ratio in the range (0, 1] of non-zero component in the random projection matrix.
If density = ‘auto’, the value is set to the minimum density as recommended by Ping Li et al.: 1 / sqrt(n_features).
Use density = 1 / 3.0 if you want to reproduce the results from Achlioptas, 2001.
Parameter to control the quality of the embedding according to the Johnson-Lindenstrauss lemma when n_components is set to ‘auto’. This value should be strictly positive.
Smaller values lead to better embedding and higher number of dimensions (n_components) in the target projection space.
If True, ensure that the output of the random projection is a dense numpy array even if the input and random projection matrix are both sparse. In practice, if the number of components is small the number of zero components in the projected data will be very small and it will be more CPU and memory efficient to use a dense representation.
If False, the projected data uses a sparse representation if the input is sparse.
Controls the pseudo random number generator used to generate the projection matrix at fit time. Pass an int for reproducible output across multiple function calls. See Glossary.
Concrete number of components computed when n_components=”auto”.
Random matrix used for the projection. Sparse matrix will be of CSR format.
Concrete density computed from when density = “auto”.
See also
Ping Li, T. Hastie and K. W. Church, 2006, “Very Sparse Random Projections”. https://web.stanford.edu/~hastie/Papers/Ping/KDD06_rp.pdf
D. Achlioptas, 2001, “Database-friendly random projections”, https://users.soe.ucsc.edu/~optas/papers/jl.pdf
fit(X[, y])
Generate a sparse random projection matrix.
fit_transform(X[, y])
Fit to data, then transform it.
get_params([deep])
Get parameters for this estimator.
set_params(**params)
Set the parameters of this estimator.
transform(X)
Project the data by using matrix product with the random matrix
Generate a sparse random projection matrix.
Training set: only the shape is used to find optimal random matrix dimensions based on the theory referenced in the afore mentioned papers.
Ignored
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 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.
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.
Project the data by using matrix product with the random matrix
The input data to project into a smaller dimensional space.
Projected array.


Reduce dimensionality through sparse random projection.
Sparse random matrix is an alternative to dense random projection matrix that guarantees similar embedding quality while being much more memory efficient and allowing faster computation of the projected data.
If we note s = 1 / density the components of the random matrix are drawn from:
Read more in the User Guide.
New in version 0.13.
Dimensionality of the target projection space.
n_components can be automatically adjusted according to the number of samples in the dataset and the bound given by the Johnson-Lindenstrauss lemma. In that case the quality of the embedding is controlled by the eps parameter.
It should be noted that Johnson-Lindenstrauss lemma can yield very conservative estimated of the required number of components as it makes no assumption on the structure of the dataset.
Ratio in the range (0, 1] of non-zero component in the random projection matrix.
If density = ‘auto’, the value is set to the minimum density as recommended by Ping Li et al.: 1 / sqrt(n_features).
Use density = 1 / 3.0 if you want to reproduce the results from Achlioptas, 2001.
Parameter to control the quality of the embedding according to the Johnson-Lindenstrauss lemma when n_components is set to ‘auto’. This value should be strictly positive.
Smaller values lead to better embedding and higher number of dimensions (n_components) in the target projection space.
If True, ensure that the output of the random projection is a dense numpy array even if the input and random projection matrix are both sparse. In practice, if the number of components is small the number of zero components in the projected data will be very small and it will be more CPU and memory efficient to use a dense representation.
If False, the projected data uses a sparse representation if the input is sparse.
Controls the pseudo random number generator used to generate the projection matrix at fit time. Pass an int for reproducible output across multiple function calls. See Glossary.
Concrete number of components computed when n_components=”auto”.
Random matrix used for the projection. Sparse matrix will be of CSR format.
Concrete density computed from when density = “auto”.
See also
Ping Li, T. Hastie and K. W. Church, 2006, “Very Sparse Random Projections”. https://web.stanford.edu/~hastie/Papers/Ping/KDD06_rp.pdf
D. Achlioptas, 2001, “Database-friendly random projections”, https://users.soe.ucsc.edu/~optas/papers/jl.pdf
fit(X[, y])
Generate a sparse random projection matrix.
fit_transform(X[, y])
Fit to data, then transform it.
get_params([deep])
Get parameters for this estimator.
set_params(**params)
Set the parameters of this estimator.
transform(X)
Project the data by using matrix product with the random matrix
Generate a sparse random projection matrix.
Training set: only the shape is used to find optimal random matrix dimensions based on the theory referenced in the afore mentioned papers.
Ignored
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 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.
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.
Project the data by using matrix product with the random matrix
The input data to project into a smaller dimensional space.
Projected array.
Manifold learning on handwritten digits: Locally Linear Embedding, Isomap…
The Johnson-Lindenstrauss bound for embedding with random projections


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 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.


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.


Label Propagation classifier
Read more in the User Guide.
String identifier for kernel function to use or the kernel function itself. Only ‘rbf’ and ‘knn’ strings are valid inputs. The function passed should take two inputs, each of shape (n_samples, n_features), and return a (n_samples, n_samples) shaped weight matrix.
Parameter for rbf kernel.
Parameter for knn kernel which need to be strictly positive.
Change maximum number of iterations allowed.
Convergence tolerance: threshold to consider the system at steady state.
The number of parallel jobs to run. None means 1 unless in a joblib.parallel_backend context. -1 means using all processors. See Glossary for more details.
Input array.
The distinct labels used in classifying instances.
Categorical distribution for each item.
Label assigned to each item via the transduction.
Number of iterations run.
See also
Alternate label propagation strategy more robust to noise.
Xiaojin Zhu and Zoubin Ghahramani. Learning from labeled and unlabeled data with label propagation. Technical Report CMU-CALD-02-107, Carnegie Mellon University, 2002 http://pages.cs.wisc.edu/~jerryzhu/pub/CMU-CALD-02-107.pdf
fit(X, y)
Fit a semi-supervised label propagation model based
get_params([deep])
Get parameters for this estimator.
predict(X)
Performs inductive inference across the model.
predict_proba(X)
Predict probability for each possible outcome.
score(X, y[, sample_weight])
Return the mean accuracy on the given test data and labels.
set_params(**params)
Set the parameters of this estimator.
Fit a semi-supervised label propagation model based
All the input data is provided matrix X (labeled and unlabeled) and corresponding label matrix y with a dedicated marker value for unlabeled samples.
A matrix of shape (n_samples, n_samples) will be created from this.
n_labeled_samples (unlabeled points are marked as -1) All unlabeled samples will be transductively assigned labels.
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.
Performs inductive inference across the model.
The data matrix.
Predictions for input data.
Predict probability for each possible outcome.
Compute the probability estimates for each single sample in X and each possible outcome seen during training (categorical distribution).
The data matrix.
Normalized probability distributions across class labels.
Return the mean accuracy on the given test data and labels.
In multi-label classification, this is the subset accuracy which is a harsh metric since you require for each sample that each label set be correctly predicted.
Test samples.
True labels for X.
Sample weights.
Mean accuracy of self.predict(X) wrt. y.
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.


Fit a semi-supervised label propagation model based
All the input data is provided matrix X (labeled and unlabeled) and corresponding label matrix y with a dedicated marker value for unlabeled samples.
A matrix of shape (n_samples, n_samples) will be created from this.
n_labeled_samples (unlabeled points are marked as -1) All unlabeled samples will be transductively assigned labels.


Performs inductive inference across the model.
The data matrix.
Predictions for input data.


Predict probability for each possible outcome.
Compute the probability estimates for each single sample in X and each possible outcome seen during training (categorical distribution).
The data matrix.
Normalized probability distributions across class labels.


Return the mean accuracy on the given test data and labels.
In multi-label classification, this is the subset accuracy which is a harsh metric since you require for each sample that each label set be correctly predicted.
Test samples.
True labels for X.
Sample weights.
Mean accuracy of self.predict(X) wrt. y.


LabelSpreading model for semi-supervised learning
This model is similar to the basic Label Propagation algorithm, but uses affinity matrix based on the normalized graph Laplacian and soft clamping across the labels.
Read more in the User Guide.
String identifier for kernel function to use or the kernel function itself. Only ‘rbf’ and ‘knn’ strings are valid inputs. The function passed should take two inputs, each of shape (n_samples, n_features), and return a (n_samples, n_samples) shaped weight matrix.
Parameter for rbf kernel.
Parameter for knn kernel which is a strictly positive integer.
Clamping factor. A value in (0, 1) that specifies the relative amount that an instance should adopt the information from its neighbors as opposed to its initial label. alpha=0 means keeping the initial label information; alpha=1 means replacing all initial information.
Maximum number of iterations allowed.
Convergence tolerance: threshold to consider the system at steady state.
The number of parallel jobs to run. None means 1 unless in a joblib.parallel_backend context. -1 means using all processors. See Glossary for more details.
Input array.
The distinct labels used in classifying instances.
Categorical distribution for each item.
Label assigned to each item via the transduction.
Number of iterations run.
See also
Unregularized graph based semi-supervised learning.
Dengyong Zhou, Olivier Bousquet, Thomas Navin Lal, Jason Weston, Bernhard Schoelkopf. Learning with local and global consistency (2004) http://citeseer.ist.psu.edu/viewdoc/summary?doi=10.1.1.115.3219
fit(X, y)
Fit a semi-supervised label propagation model based
get_params([deep])
Get parameters for this estimator.
predict(X)
Performs inductive inference across the model.
predict_proba(X)
Predict probability for each possible outcome.
score(X, y[, sample_weight])
Return the mean accuracy on the given test data and labels.
set_params(**params)
Set the parameters of this estimator.
Fit a semi-supervised label propagation model based
All the input data is provided matrix X (labeled and unlabeled) and corresponding label matrix y with a dedicated marker value for unlabeled samples.
A matrix of shape (n_samples, n_samples) will be created from this.
n_labeled_samples (unlabeled points are marked as -1) All unlabeled samples will be transductively assigned labels.
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.
Performs inductive inference across the model.
The data matrix.
Predictions for input data.
Predict probability for each possible outcome.
Compute the probability estimates for each single sample in X and each possible outcome seen during training (categorical distribution).
The data matrix.
Normalized probability distributions across class labels.
Return the mean accuracy on the given test data and labels.
In multi-label classification, this is the subset accuracy which is a harsh metric since you require for each sample that each label set be correctly predicted.
Test samples.
True labels for X.
Sample weights.
Mean accuracy of self.predict(X) wrt. y.
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.


LabelSpreading model for semi-supervised learning
This model is similar to the basic Label Propagation algorithm, but uses affinity matrix based on the normalized graph Laplacian and soft clamping across the labels.
Read more in the User Guide.
String identifier for kernel function to use or the kernel function itself. Only ‘rbf’ and ‘knn’ strings are valid inputs. The function passed should take two inputs, each of shape (n_samples, n_features), and return a (n_samples, n_samples) shaped weight matrix.
Parameter for rbf kernel.
Parameter for knn kernel which is a strictly positive integer.
Clamping factor. A value in (0, 1) that specifies the relative amount that an instance should adopt the information from its neighbors as opposed to its initial label. alpha=0 means keeping the initial label information; alpha=1 means replacing all initial information.
Maximum number of iterations allowed.
Convergence tolerance: threshold to consider the system at steady state.
The number of parallel jobs to run. None means 1 unless in a joblib.parallel_backend context. -1 means using all processors. See Glossary for more details.
Input array.
The distinct labels used in classifying instances.
Categorical distribution for each item.
Label assigned to each item via the transduction.
Number of iterations run.
See also
Unregularized graph based semi-supervised learning.
Dengyong Zhou, Olivier Bousquet, Thomas Navin Lal, Jason Weston, Bernhard Schoelkopf. Learning with local and global consistency (2004) http://citeseer.ist.psu.edu/viewdoc/summary?doi=10.1.1.115.3219
fit(X, y)
Fit a semi-supervised label propagation model based
get_params([deep])
Get parameters for this estimator.
predict(X)
Performs inductive inference across the model.
predict_proba(X)
Predict probability for each possible outcome.
score(X, y[, sample_weight])
Return the mean accuracy on the given test data and labels.
set_params(**params)
Set the parameters of this estimator.
Fit a semi-supervised label propagation model based
All the input data is provided matrix X (labeled and unlabeled) and corresponding label matrix y with a dedicated marker value for unlabeled samples.
A matrix of shape (n_samples, n_samples) will be created from this.
n_labeled_samples (unlabeled points are marked as -1) All unlabeled samples will be transductively assigned labels.
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.
Performs inductive inference across the model.
The data matrix.
Predictions for input data.
Predict probability for each possible outcome.
Compute the probability estimates for each single sample in X and each possible outcome seen during training (categorical distribution).
The data matrix.
Normalized probability distributions across class labels.
Return the mean accuracy on the given test data and labels.
In multi-label classification, this is the subset accuracy which is a harsh metric since you require for each sample that each label set be correctly predicted.
Test samples.
True labels for X.
Sample weights.
Mean accuracy of self.predict(X) wrt. y.
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.
Label Propagation learning a complex structure
Label Propagation digits: Demonstrating performance
Decision boundary of semi-supervised classifiers versus SVM on the Iris dataset
Semi-supervised Classification on a Text Dataset
Label Propagation digits active learning


Self-training classifier.
This class allows a given supervised classifier to function as a semi-supervised classifier, allowing it to learn from unlabeled data. It does this by iteratively predicting pseudo-labels for the unlabeled data and adding them to the training set.
The classifier will continue iterating until either max_iter is reached, or no pseudo-labels were added to the training set in the previous iteration.
Read more in the User Guide.
An estimator object implementing fit and predict_proba. Invoking the fit method will fit a clone of the passed estimator, which will be stored in the base_estimator_ attribute.
The selection criterion used to select which labels to add to the training set. If ‘threshold’, pseudo-labels with prediction probabilities above threshold are added to the dataset. If ‘k_best’, the k_best pseudo-labels with highest prediction probabilities are added to the dataset. When using the ‘threshold’ criterion, a well calibrated classifier should be used.
The decision threshold for use with criterion='threshold'. Should be in [0, 1). When using the ‘threshold’ criterion, a well calibrated classifier should be used.
The amount of samples to add in each iteration. Only used when criterion is k_best’.
Maximum number of iterations allowed. Should be greater than or equal to 0. If it is None, the classifier will continue to predict labels until no new pseudo-labels are added, or all unlabeled samples have been labeled.
Enable verbose output.
The fitted estimator.
Class labels for each output. (Taken from the trained base_estimator_).
The labels used for the final fit of the classifier, including pseudo-labels added during fit.
The iteration in which each sample was labeled. When a sample has iteration 0, the sample was already labeled in the original dataset. When a sample has iteration -1, the sample was not labeled in any iteration.
The number of rounds of self-training, that is the number of times the base estimator is fitted on relabeled variants of the training set.
The reason that fitting was stopped.
David Yarowsky. 1995. Unsupervised word sense disambiguation rivaling supervised methods. In Proceedings of the 33rd annual meeting on Association for Computational Linguistics (ACL ‘95). Association for Computational Linguistics, Stroudsburg, PA, USA, 189-196. DOI: https://doi.org/10.3115/981658.981684
decision_function(X)
Calls decision function of the base_estimator.
fit(X, y)
Fits this SelfTrainingClassifier to a dataset.
get_params([deep])
Get parameters for this estimator.
predict(X)
Predict the classes of X.
predict_log_proba(X)
Predict log probability for each possible outcome.
predict_proba(X)
Predict probability for each possible outcome.
score(X, y)
Calls score on the base_estimator.
set_params(**params)
Set the parameters of this estimator.
Calls decision function of the base_estimator.
Array representing the data.
Result of the decision function of the base_estimator.
Fits this SelfTrainingClassifier to a dataset.
Array representing the data.
Array representing the labels. Unlabeled samples should have the label -1.
Returns an instance of self.
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.
Predict the classes of X.
Array representing the data.
Array with predicted labels.
Predict log probability for each possible outcome.
Array representing the data.
Array with log prediction probabilities.
Predict probability for each possible outcome.
Array representing the data.
Array with prediction probabilities.
Calls score on the base_estimator.
Array representing the data.
Array representing the labels.
Result of calling score on the base_estimator.
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.


Self-training classifier.
This class allows a given supervised classifier to function as a semi-supervised classifier, allowing it to learn from unlabeled data. It does this by iteratively predicting pseudo-labels for the unlabeled data and adding them to the training set.
The classifier will continue iterating until either max_iter is reached, or no pseudo-labels were added to the training set in the previous iteration.
Read more in the User Guide.
An estimator object implementing fit and predict_proba. Invoking the fit method will fit a clone of the passed estimator, which will be stored in the base_estimator_ attribute.
The selection criterion used to select which labels to add to the training set. If ‘threshold’, pseudo-labels with prediction probabilities above threshold are added to the dataset. If ‘k_best’, the k_best pseudo-labels with highest prediction probabilities are added to the dataset. When using the ‘threshold’ criterion, a well calibrated classifier should be used.
The decision threshold for use with criterion='threshold'. Should be in [0, 1). When using the ‘threshold’ criterion, a well calibrated classifier should be used.
The amount of samples to add in each iteration. Only used when criterion is k_best’.
Maximum number of iterations allowed. Should be greater than or equal to 0. If it is None, the classifier will continue to predict labels until no new pseudo-labels are added, or all unlabeled samples have been labeled.
Enable verbose output.
The fitted estimator.
Class labels for each output. (Taken from the trained base_estimator_).
The labels used for the final fit of the classifier, including pseudo-labels added during fit.
The iteration in which each sample was labeled. When a sample has iteration 0, the sample was already labeled in the original dataset. When a sample has iteration -1, the sample was not labeled in any iteration.
The number of rounds of self-training, that is the number of times the base estimator is fitted on relabeled variants of the training set.
The reason that fitting was stopped.
David Yarowsky. 1995. Unsupervised word sense disambiguation rivaling supervised methods. In Proceedings of the 33rd annual meeting on Association for Computational Linguistics (ACL ‘95). Association for Computational Linguistics, Stroudsburg, PA, USA, 189-196. DOI: https://doi.org/10.3115/981658.981684
decision_function(X)
Calls decision function of the base_estimator.
fit(X, y)
Fits this SelfTrainingClassifier to a dataset.
get_params([deep])
Get parameters for this estimator.
predict(X)
Predict the classes of X.
predict_log_proba(X)
Predict log probability for each possible outcome.
predict_proba(X)
Predict probability for each possible outcome.
score(X, y)
Calls score on the base_estimator.
set_params(**params)
Set the parameters of this estimator.
Calls decision function of the base_estimator.
Array representing the data.
Result of the decision function of the base_estimator.
Fits this SelfTrainingClassifier to a dataset.
Array representing the data.
Array representing the labels. Unlabeled samples should have the label -1.
Returns an instance of self.
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.
Predict the classes of X.
Array representing the data.
Array with predicted labels.
Predict log probability for each possible outcome.
Array representing the data.
Array with log prediction probabilities.
Predict probability for each possible outcome.
Array representing the data.
Array with prediction probabilities.
Calls score on the base_estimator.
Array representing the data.
Array representing the labels.
Result of calling score on the base_estimator.
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.
Release Highlights for scikit-learn 0.24
Decision boundary of semi-supervised classifiers versus SVM on the Iris dataset
Effect of varying threshold for self-training
Semi-supervised Classification on a Text Dataset


Calls decision function of the base_estimator.
Array representing the data.
Result of the decision function of the base_estimator.


Fits this SelfTrainingClassifier to a dataset.
Array representing the data.
Array representing the labels. Unlabeled samples should have the label -1.
Returns an instance of self.


Predict the classes of X.
Array representing the data.
Array with predicted labels.


Predict log probability for each possible outcome.
Array representing the data.
Array with log prediction probabilities.


Predict probability for each possible outcome.
Array representing the data.
Array with prediction probabilities.


Calls score on the base_estimator.
Array representing the data.
Array representing the labels.
Result of calling score on the base_estimator.


Set global scikit-learn configuration
New in version 0.19.
If True, validation for finiteness will be skipped, saving time, but leading to potential crashes. If False, validation for finiteness will be performed, avoiding error. Global default: False.
New in version 0.19.
If set, scikit-learn will attempt to limit the size of temporary arrays to this number of MiB (per job when parallelised), often saving both computation time and memory on expensive operations that can be performed in chunks. Global default: 1024.
New in version 0.20.
If True, only the parameters that were set to non-default values will be printed when printing an estimator. For example, print(SVC()) while True will only print ‘SVC()’ while the default behaviour would be to print ‘SVC(C=1.0, cache_size=200, …)’ with all the non-changed parameters.
New in version 0.21.
If ‘diagram’, estimators will be displayed as a diagram in a Jupyter lab or notebook context. If ‘text’, estimators will be displayed as text. Default is ‘text’.
New in version 0.23.
See also
Context manager for global scikit-learn configuration.
Retrieve current values of the global configuration.


Print useful debugging information”
New in version 0.20.


Constructs a new unfitted estimator with the same parameters.
Clone does a deep copy of the model in an estimator without actually copying attached data. It yields a new estimator with the same parameters that has not been fitted on any data.
If the estimator’s random_state parameter is an integer (or if the estimator doesn’t have a random_state parameter), an exact clone is returned: the clone and the original estimator will give the exact same results. Otherwise, statistical clone is returned: the clone might yield different results from the original estimator. More details can be found in Controlling randomness.
The estimator or group of estimators to be cloned.
If safe is False, clone will fall back to a deep copy on objects that are not estimators.


Return True if the given estimator is (probably) a classifier.
Estimator object to test.
True if estimator is a classifier and False otherwise.


Return True if the given estimator is (probably) a regressor.
Estimator object to test.
True if estimator is a regressor and False otherwise.


Compute true and predicted probabilities for a calibration curve.
The method assumes the inputs come from a binary classifier, and discretize the [0, 1] interval into bins.
Calibration curves may also be referred to as reliability diagrams.
Read more in the User Guide.
True targets.
Probabilities of the positive class.
Whether y_prob needs to be normalized into the [0, 1] interval, i.e. is not a proper probability. If True, the smallest value in y_prob is linearly mapped onto 0 and the largest one onto 1.
Number of bins to discretize the [0, 1] interval. A bigger number requires more data. Bins with no samples (i.e. without corresponding values in y_prob) will not be returned, thus the returned arrays may have less than n_bins values.
Strategy used to define the widths of the bins.
The bins have identical widths.
The bins have the same number of samples and depend on y_prob.
The proportion of samples whose class is the positive class, in each bin (fraction of positives).
The mean predicted probability in each bin.
Alexandru Niculescu-Mizil and Rich Caruana (2005) Predicting Good Probabilities With Supervised Learning, in Proceedings of the 22nd International Conference on Machine Learning (ICML). See section 4 (Qualitative Analysis of Predictions).
Comparison of Calibration of Classifiers
Probability Calibration curves


Perform Affinity Propagation Clustering of data.
Read more in the User Guide.
Matrix of similarities between points.
Preferences for each point - points with larger values of preferences are more likely to be chosen as exemplars. The number of exemplars, i.e. of clusters, is influenced by the input preferences value. If the preferences are not passed as arguments, they will be set to the median of the input similarities (resulting in a moderate number of clusters). For a smaller amount of clusters, this can be set to the minimum value of the similarities.
Number of iterations with no change in the number of estimated clusters that stops the convergence.
Maximum number of iterations
Damping factor between 0.5 and 1.
If copy is False, the affinity matrix is modified inplace by the algorithm, for memory efficiency.
The verbosity level.
Whether or not to return the number of iterations.
Pseudo-random number generator to control the starting state. Use an int for reproducible results across function calls. See the Glossary.
New in version 0.23: this parameter was previously hardcoded as 0.
Index of clusters centers.
Cluster labels for each point.
Number of iterations run. Returned only if return_n_iter is set to True.
For an example, see examples/cluster/plot_affinity_propagation.py.
When the algorithm does not converge, it returns an empty array as cluster_center_indices and -1 as label for each training sample.
When all training samples have equal similarities and equal preferences, the assignment of cluster centers and labels depends on the preference. If the preference is smaller than the similarities, a single cluster center and label 0 for every sample will be returned. Otherwise, every training sample becomes its own cluster center and is assigned a unique label.
Brendan J. Frey and Delbert Dueck, “Clustering by Passing Messages Between Data Points”, Science Feb. 2007
Visualizing the stock market structure


Performs DBSCAN extraction for an arbitrary epsilon.
Extracting the clusters runs in linear time. Note that this results in labels_ which are close to a DBSCAN with similar settings and eps, only if eps is close to max_eps.
Reachability distances calculated by OPTICS (reachability_)
Distances at which points become core (core_distances_)
OPTICS ordered point indices (ordering_)
DBSCAN eps parameter. Must be set to < max_eps. Results will be close to DBSCAN algorithm if eps and max_eps are close to one another.
The estimated labels.
Demo of OPTICS clustering algorithm


Automatically extract clusters according to the Xi-steep method.
Reachability distances calculated by OPTICS (reachability_)
Predecessors calculated by OPTICS.
OPTICS ordered point indices (ordering_)
The same as the min_samples given to OPTICS. Up and down steep regions can’t have more then min_samples consecutive non-steep points. Expressed as an absolute number or a fraction of the number of samples (rounded to be at least 2).
Minimum number of samples in an OPTICS cluster, expressed as an absolute number or a fraction of the number of samples (rounded to be at least 2). If None, the value of min_samples is used instead.
Determines the minimum steepness on the reachability plot that constitutes a cluster boundary. For example, an upwards point in the reachability plot is defined by the ratio from one point to its successor being at most 1-xi.
Correct clusters based on the calculated predecessors.
The labels assigned to samples. Points which are not included in any cluster are labeled as -1.
The list of clusters in the form of [start, end] in each row, with all indices inclusive. The clusters are ordered according to (end,
-start) (ascending) so that larger clusters encompassing smaller clusters come after such nested smaller clusters. Since labels does not reflect the hierarchy, usually len(clusters) >
np.unique(labels).


Computes the OPTICS reachability graph.
Read more in the User Guide.
A feature array, or array of distances between samples if metric=’precomputed’
The number of samples in a neighborhood for a point to be considered as a core point. Expressed as an absolute number or a fraction of the number of samples (rounded to be at least 2).
The maximum distance between two samples for one to be considered as in the neighborhood of the other. Default value of np.inf will identify clusters across all scales; reducing max_eps will result in shorter run times.
Metric to use for distance computation. Any metric from scikit-learn or scipy.spatial.distance can be used.
If metric is a callable function, it is called on each pair of instances (rows) and the resulting value recorded. The callable should take two arrays as input and return one value indicating the distance between them. This works for Scipy’s metrics, but is less efficient than passing the metric name as a string. If metric is “precomputed”, X is assumed to be a distance matrix and must be square.
Valid values for metric are:
See the documentation for scipy.spatial.distance for details on these metrics.
Parameter for the Minkowski metric from pairwise_distances. When p = 1, this is equivalent to using manhattan_distance (l1), and euclidean_distance (l2) for p = 2. For arbitrary p, minkowski_distance (l_p) is used.
Additional keyword arguments for the metric function.
Algorithm used to compute the nearest neighbors:
Note: fitting on sparse input will override the setting of this parameter, using brute force.
Leaf size passed to BallTree or KDTree. This can affect the speed of the construction and query, as well as the memory required to store the tree. The optimal value depends on the nature of the problem.
The number of parallel jobs to run for neighbors search. None means 1 unless in a joblib.parallel_backend context. -1 means using all processors. See Glossary for more details.
The cluster ordered list of sample indices.
Distance at which each sample becomes a core point, indexed by object order. Points which will never be core have a distance of inf. Use clust.core_distances_[clust.ordering_] to access in cluster order.
Reachability distances per sample, indexed by object order. Use clust.reachability_[clust.ordering_] to access in cluster order.
Point that a sample was reached from, indexed by object order. Seed points have a predecessor of -1.
Ankerst, Mihael, Markus M. Breunig, Hans-Peter Kriegel, and Jörg Sander. “OPTICS: ordering points to identify the clustering structure.” ACM SIGMOD Record 28, no. 2 (1999): 49-60.