Transform X to a cluster-distance space.
In the new space, each dimension is the distance to the cluster centers. Note that even if X is sparse, the array returned by transform will typically be dense.
New data to transform.
X transformed in the new space.


Estimate clustering structure from vector array.
OPTICS (Ordering Points To Identify the Clustering Structure), closely related to DBSCAN, finds core sample of high density and expands clusters from them [1]. Unlike DBSCAN, keeps cluster hierarchy for a variable neighborhood radius. Better suited for usage on large datasets than the current sklearn implementation of DBSCAN.
Clusters are then extracted using a DBSCAN-like method (cluster_method = ‘dbscan’) or an automatic technique proposed in [1] (cluster_method = ‘xi’).
This implementation deviates from the original OPTICS by first performing k-nearest-neighborhood searches on all points to identify core sizes, then computing only the distances to unprocessed points when constructing the cluster order. Note that we do not employ a heap to manage the expansion candidates, so the time complexity will be O(n^2).
Read more in the User Guide.
The number of samples in a neighborhood for a point to be considered as a core point. Also, up and down steep regions can’t have more than 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).
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.
The extraction method used to extract clusters using the calculated reachability and ordering. Possible values are “xi” and “dbscan”.
The maximum distance between two samples for one to be considered as in the neighborhood of the other. By default it assumes the same value as max_eps. Used only when cluster_method='dbscan'.
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. Used only when cluster_method='xi'.
Correct clusters according to the predecessors calculated by OPTICS [2]. This parameter has minimal effect on most datasets. Used only when cluster_method='xi'.
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. Used only when cluster_method='xi'.
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.
Cluster labels for each point in the dataset given to fit(). Noisy samples and points which are not included in a leaf cluster of cluster_hierarchy_ are labeled as -1.
Reachability distances per sample, indexed by object order. Use clust.reachability_[clust.ordering_] to access in cluster order.
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.
Point that a sample was reached from, indexed by object order. Seed points have a predecessor of -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 those smaller ones. Since labels_ does not reflect the hierarchy, usually len(cluster_hierarchy_) > np.unique(optics.labels_). Please also note that these indices are of the ordering_, i.e. X[ordering_][start:end + 1] form a cluster. Only available when cluster_method='xi'.
See also
A similar clustering for a specified neighborhood radius (eps). Our implementation is optimized for runtime.
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.
Schubert, Erich, Michael Gertz. “Improving the Cluster Structure Extracted from OPTICS Plots.” Proc. of the Conference “Lernen, Wissen, Daten, Analysen” (LWDA) (2018): 318-329.
fit(X[, y])
Perform OPTICS clustering.
fit_predict(X[, y])
Perform clustering on X and returns cluster labels.
get_params([deep])
Get parameters for this estimator.
set_params(**params)
Set the parameters of this estimator.
Perform OPTICS clustering.
Extracts an ordered list of points and reachability distances, and performs initial clustering using max_eps distance specified at OPTICS object instantiation.
A feature array, or array of distances between samples if metric=’precomputed’.
Ignored.
The instance.
Perform clustering on X and returns cluster labels.
Input data.
Not used, present for API consistency by convention.
Cluster 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.
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.


Estimate clustering structure from vector array.
OPTICS (Ordering Points To Identify the Clustering Structure), closely related to DBSCAN, finds core sample of high density and expands clusters from them [1]. Unlike DBSCAN, keeps cluster hierarchy for a variable neighborhood radius. Better suited for usage on large datasets than the current sklearn implementation of DBSCAN.
Clusters are then extracted using a DBSCAN-like method (cluster_method = ‘dbscan’) or an automatic technique proposed in [1] (cluster_method = ‘xi’).
This implementation deviates from the original OPTICS by first performing k-nearest-neighborhood searches on all points to identify core sizes, then computing only the distances to unprocessed points when constructing the cluster order. Note that we do not employ a heap to manage the expansion candidates, so the time complexity will be O(n^2).
Read more in the User Guide.
The number of samples in a neighborhood for a point to be considered as a core point. Also, up and down steep regions can’t have more than 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).
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.
The extraction method used to extract clusters using the calculated reachability and ordering. Possible values are “xi” and “dbscan”.
The maximum distance between two samples for one to be considered as in the neighborhood of the other. By default it assumes the same value as max_eps. Used only when cluster_method='dbscan'.
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. Used only when cluster_method='xi'.
Correct clusters according to the predecessors calculated by OPTICS [2]. This parameter has minimal effect on most datasets. Used only when cluster_method='xi'.
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. Used only when cluster_method='xi'.
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.
Cluster labels for each point in the dataset given to fit(). Noisy samples and points which are not included in a leaf cluster of cluster_hierarchy_ are labeled as -1.
Reachability distances per sample, indexed by object order. Use clust.reachability_[clust.ordering_] to access in cluster order.
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.
Point that a sample was reached from, indexed by object order. Seed points have a predecessor of -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 those smaller ones. Since labels_ does not reflect the hierarchy, usually len(cluster_hierarchy_) > np.unique(optics.labels_). Please also note that these indices are of the ordering_, i.e. X[ordering_][start:end + 1] form a cluster. Only available when cluster_method='xi'.
See also
A similar clustering for a specified neighborhood radius (eps). Our implementation is optimized for runtime.
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.
Schubert, Erich, Michael Gertz. “Improving the Cluster Structure Extracted from OPTICS Plots.” Proc. of the Conference “Lernen, Wissen, Daten, Analysen” (LWDA) (2018): 318-329.
fit(X[, y])
Perform OPTICS clustering.
fit_predict(X[, y])
Perform clustering on X and returns cluster labels.
get_params([deep])
Get parameters for this estimator.
set_params(**params)
Set the parameters of this estimator.
Perform OPTICS clustering.
Extracts an ordered list of points and reachability distances, and performs initial clustering using max_eps distance specified at OPTICS object instantiation.
A feature array, or array of distances between samples if metric=’precomputed’.
Ignored.
The instance.
Perform clustering on X and returns cluster labels.
Input data.
Not used, present for API consistency by convention.
Cluster 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.
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.
Demo of OPTICS clustering algorithm
Comparing different clustering algorithms on toy datasets


Perform OPTICS clustering.
Extracts an ordered list of points and reachability distances, and performs initial clustering using max_eps distance specified at OPTICS object instantiation.
A feature array, or array of distances between samples if metric=’precomputed’.
Ignored.
The instance.


Perform clustering on X and returns cluster labels.
Input data.
Not used, present for API consistency by convention.
Cluster 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.


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.


Spectral biclustering (Kluger, 2003).
Partitions rows and columns under the assumption that the data has an underlying checkerboard structure. For instance, if there are two row partitions and three column partitions, each row will belong to three biclusters, and each column will belong to two biclusters. The outer product of the corresponding row and column label vectors gives this checkerboard structure.
Read more in the User Guide.
The number of row and column clusters in the checkerboard structure.
Method of normalizing and converting singular vectors into biclusters. May be one of ‘scale’, ‘bistochastic’, or ‘log’. The authors recommend using ‘log’. If the data is sparse, however, log normalization will not work, which is why the default is ‘bistochastic’.
Warning
if method='log', the data must be sparse.
Number of singular vectors to check.
Number of best singular vectors to which to project the data for clustering.
Selects the algorithm for finding singular vectors. May be ‘randomized’ or ‘arpack’. If ‘randomized’, uses randomized_svd, which may be faster for large matrices. If ‘arpack’, uses scipy.sparse.linalg.svds, which is more accurate, but possibly slower in some cases.
Number of vectors to use in calculating the SVD. Corresponds to ncv when svd_method=arpack and n_oversamples when svd_method is ‘randomized`.
Whether to use mini-batch k-means, which is faster but may get different results.
Method for initialization of k-means algorithm; defaults to ‘k-means++’.
Number of random initializations that are tried with the k-means algorithm.
If mini-batch k-means is used, the best initialization is chosen and the algorithm runs once. Otherwise, the algorithm is run for each initialization and the best solution chosen.
The number of jobs to use for the computation. This works by breaking down the pairwise matrix into n_jobs even slices and computing them in parallel.
None means 1 unless in a joblib.parallel_backend context. -1 means using all processors. See Glossary for more details.
Deprecated since version 0.23: n_jobs was deprecated in version 0.23 and will be removed in 1.0 (renaming of 0.25).
Used for randomizing the singular value decomposition and the k-means initialization. Use an int to make the randomness deterministic. See Glossary.
Results of the clustering. rows[i, r] is True if cluster i contains row r. Available only after calling fit.
Results of the clustering, like rows.
Row partition labels.
Column partition labels.
fit(X[, y])
Creates a biclustering for X.
get_indices(i)
Row and column indices of the i’th bicluster.
get_params([deep])
Get parameters for this estimator.
get_shape(i)
Shape of the i’th bicluster.
get_submatrix(i, data)
Return the submatrix corresponding to bicluster i.
set_params(**params)
Set the parameters of this estimator.
Convenient way to get row and column indicators together.
Returns the rows_ and columns_ members.
Creates a biclustering for X.
Row and column indices of the i’th bicluster.
Only works if rows_ and columns_ attributes exist.
The index of the cluster.
Indices of rows in the dataset that belong to the bicluster.
Indices of columns in the dataset that belong to the bicluster.
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.
Shape of the i’th bicluster.
The index of the cluster.
Number of rows in the bicluster.
Number of columns in the bicluster.
Return the submatrix corresponding to bicluster i.
The index of the cluster.
The data.
The submatrix corresponding to bicluster i.
Works with sparse matrices. Only works if rows_ and columns_ attributes exist.
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.


Spectral biclustering (Kluger, 2003).
Partitions rows and columns under the assumption that the data has an underlying checkerboard structure. For instance, if there are two row partitions and three column partitions, each row will belong to three biclusters, and each column will belong to two biclusters. The outer product of the corresponding row and column label vectors gives this checkerboard structure.
Read more in the User Guide.
The number of row and column clusters in the checkerboard structure.
Method of normalizing and converting singular vectors into biclusters. May be one of ‘scale’, ‘bistochastic’, or ‘log’. The authors recommend using ‘log’. If the data is sparse, however, log normalization will not work, which is why the default is ‘bistochastic’.
Warning
if method='log', the data must be sparse.
Number of singular vectors to check.
Number of best singular vectors to which to project the data for clustering.
Selects the algorithm for finding singular vectors. May be ‘randomized’ or ‘arpack’. If ‘randomized’, uses randomized_svd, which may be faster for large matrices. If ‘arpack’, uses scipy.sparse.linalg.svds, which is more accurate, but possibly slower in some cases.
Number of vectors to use in calculating the SVD. Corresponds to ncv when svd_method=arpack and n_oversamples when svd_method is ‘randomized`.
Whether to use mini-batch k-means, which is faster but may get different results.
Method for initialization of k-means algorithm; defaults to ‘k-means++’.
Number of random initializations that are tried with the k-means algorithm.
If mini-batch k-means is used, the best initialization is chosen and the algorithm runs once. Otherwise, the algorithm is run for each initialization and the best solution chosen.
The number of jobs to use for the computation. This works by breaking down the pairwise matrix into n_jobs even slices and computing them in parallel.
None means 1 unless in a joblib.parallel_backend context. -1 means using all processors. See Glossary for more details.
Deprecated since version 0.23: n_jobs was deprecated in version 0.23 and will be removed in 1.0 (renaming of 0.25).
Used for randomizing the singular value decomposition and the k-means initialization. Use an int to make the randomness deterministic. See Glossary.
Results of the clustering. rows[i, r] is True if cluster i contains row r. Available only after calling fit.
Results of the clustering, like rows.
Row partition labels.
Column partition labels.
fit(X[, y])
Creates a biclustering for X.
get_indices(i)
Row and column indices of the i’th bicluster.
get_params([deep])
Get parameters for this estimator.
get_shape(i)
Shape of the i’th bicluster.
get_submatrix(i, data)
Return the submatrix corresponding to bicluster i.
set_params(**params)
Set the parameters of this estimator.
Convenient way to get row and column indicators together.
Returns the rows_ and columns_ members.
Creates a biclustering for X.
Row and column indices of the i’th bicluster.
Only works if rows_ and columns_ attributes exist.
The index of the cluster.
Indices of rows in the dataset that belong to the bicluster.
Indices of columns in the dataset that belong to the bicluster.
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.
Shape of the i’th bicluster.
The index of the cluster.
Number of rows in the bicluster.
Number of columns in the bicluster.
Return the submatrix corresponding to bicluster i.
The index of the cluster.
The data.
The submatrix corresponding to bicluster i.
Works with sparse matrices. Only works if rows_ and columns_ attributes exist.
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.
A demo of the Spectral Biclustering algorithm


Convenient way to get row and column indicators together.
Returns the rows_ and columns_ members.


Row and column indices of the i’th bicluster.
Only works if rows_ and columns_ attributes exist.
The index of the cluster.
Indices of rows in the dataset that belong to the bicluster.
Indices of columns in the dataset that belong to the bicluster.


Shape of the i’th bicluster.
The index of the cluster.
Number of rows in the bicluster.
Number of columns in the bicluster.


Return the submatrix corresponding to bicluster i.
The index of the cluster.
The data.
The submatrix corresponding to bicluster i.
Works with sparse matrices. Only works if rows_ and columns_ attributes exist.


Apply clustering to a projection of the normalized Laplacian.
In practice Spectral Clustering is very useful when the structure of the individual clusters is highly non-convex or more generally when a measure of the center and spread of the cluster is not a suitable description of the complete cluster. For instance when clusters are nested circles on the 2D plane.
If affinity is the adjacency matrix of a graph, this method can be used to find normalized graph cuts.
When calling fit, an affinity matrix is constructed using either kernel function such the Gaussian (aka RBF) kernel of the euclidean distanced d(X, X):
or a k-nearest neighbors connectivity matrix.
Alternatively, using precomputed, a user-provided affinity matrix can be used.
Read more in the User Guide.
The dimension of the projection subspace.
The eigenvalue decomposition strategy to use. AMG requires pyamg to be installed. It can be faster on very large, sparse problems, but may also lead to instabilities. If None, then 'arpack' is used.
Number of eigen vectors to use for the spectral embedding
A pseudo random number generator used for the initialization of the lobpcg eigen vectors decomposition when eigen_solver='amg' and by the K-Means initialization. Use an int to make the randomness deterministic. See Glossary.
Number of time the k-means algorithm will be run with different centroid seeds. The final results will be the best output of n_init consecutive runs in terms of inertia.
Kernel coefficient for rbf, poly, sigmoid, laplacian and chi2 kernels. Ignored for affinity='nearest_neighbors'.
Only kernels that produce similarity scores (non-negative values that increase with similarity) should be used. This property is not checked by the clustering algorithm.
Number of neighbors to use when constructing the affinity matrix using the nearest neighbors method. Ignored for affinity='rbf'.
Stopping criterion for eigendecomposition of the Laplacian matrix when eigen_solver='arpack'.
The strategy to use to assign labels in the embedding space. There are two ways to assign labels after the laplacian embedding. k-means can be applied and is a popular choice. But it can also be sensitive to initialization. Discretization is another approach which is less sensitive to random initialization.
Degree of the polynomial kernel. Ignored by other kernels.
Zero coefficient for polynomial and sigmoid kernels. Ignored by other kernels.
Parameters (keyword arguments) and values for kernel passed as callable object. Ignored by other kernels.
The number of parallel jobs to run when affinity='nearest_neighbors' or affinity='precomputed_nearest_neighbors'. The neighbors search will be done in parallel. None means 1 unless in a joblib.parallel_backend context. -1 means using all processors. See Glossary for more details.
Verbosity mode.
New in version 0.24.
Affinity matrix used for clustering. Available only if after calling fit.
Labels of each point
If you have an affinity matrix, such as a distance matrix, for which 0 means identical elements, and high values means very dissimilar elements, it can be transformed in a similarity matrix that is well suited for the algorithm by applying the Gaussian (RBF, heat) kernel:
Where delta is a free parameter representing the width of the Gaussian kernel.
Another alternative is to take a symmetric version of the k nearest neighbors connectivity matrix of the points.
If the pyamg package is installed, it is used: this greatly speeds up computation.
fit(X[, y])
Perform spectral clustering from features, or affinity matrix.
fit_predict(X[, y])
Perform spectral clustering from features, or affinity matrix, and return cluster labels.
get_params([deep])
Get parameters for this estimator.
set_params(**params)
Set the parameters of this estimator.
Perform spectral clustering from features, or affinity matrix.
Training instances to cluster, or similarities / affinities between instances if affinity='precomputed'. If a sparse matrix is provided in a format other than csr_matrix, csc_matrix, or coo_matrix, it will be converted into a sparse csr_matrix.
Not used, present here for API consistency by convention.
Perform spectral clustering from features, or affinity matrix, and return cluster labels.
Training instances to cluster, or similarities / affinities between instances if affinity='precomputed'. If a sparse matrix is provided in a format other than csr_matrix, csc_matrix, or coo_matrix, it will be converted into a sparse csr_matrix.
Not used, present here for API consistency by convention.
Cluster 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.
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 clustering to a projection of the normalized Laplacian.
In practice Spectral Clustering is very useful when the structure of the individual clusters is highly non-convex or more generally when a measure of the center and spread of the cluster is not a suitable description of the complete cluster. For instance when clusters are nested circles on the 2D plane.
If affinity is the adjacency matrix of a graph, this method can be used to find normalized graph cuts.
When calling fit, an affinity matrix is constructed using either kernel function such the Gaussian (aka RBF) kernel of the euclidean distanced d(X, X):
or a k-nearest neighbors connectivity matrix.
Alternatively, using precomputed, a user-provided affinity matrix can be used.
Read more in the User Guide.
The dimension of the projection subspace.
The eigenvalue decomposition strategy to use. AMG requires pyamg to be installed. It can be faster on very large, sparse problems, but may also lead to instabilities. If None, then 'arpack' is used.
Number of eigen vectors to use for the spectral embedding
A pseudo random number generator used for the initialization of the lobpcg eigen vectors decomposition when eigen_solver='amg' and by the K-Means initialization. Use an int to make the randomness deterministic. See Glossary.
Number of time the k-means algorithm will be run with different centroid seeds. The final results will be the best output of n_init consecutive runs in terms of inertia.
Kernel coefficient for rbf, poly, sigmoid, laplacian and chi2 kernels. Ignored for affinity='nearest_neighbors'.
Only kernels that produce similarity scores (non-negative values that increase with similarity) should be used. This property is not checked by the clustering algorithm.
Number of neighbors to use when constructing the affinity matrix using the nearest neighbors method. Ignored for affinity='rbf'.
Stopping criterion for eigendecomposition of the Laplacian matrix when eigen_solver='arpack'.
The strategy to use to assign labels in the embedding space. There are two ways to assign labels after the laplacian embedding. k-means can be applied and is a popular choice. But it can also be sensitive to initialization. Discretization is another approach which is less sensitive to random initialization.
Degree of the polynomial kernel. Ignored by other kernels.
Zero coefficient for polynomial and sigmoid kernels. Ignored by other kernels.
Parameters (keyword arguments) and values for kernel passed as callable object. Ignored by other kernels.
The number of parallel jobs to run when affinity='nearest_neighbors' or affinity='precomputed_nearest_neighbors'. The neighbors search will be done in parallel. None means 1 unless in a joblib.parallel_backend context. -1 means using all processors. See Glossary for more details.
Verbosity mode.
New in version 0.24.
Affinity matrix used for clustering. Available only if after calling fit.
Labels of each point
If you have an affinity matrix, such as a distance matrix, for which 0 means identical elements, and high values means very dissimilar elements, it can be transformed in a similarity matrix that is well suited for the algorithm by applying the Gaussian (RBF, heat) kernel:
Where delta is a free parameter representing the width of the Gaussian kernel.
Another alternative is to take a symmetric version of the k nearest neighbors connectivity matrix of the points.
If the pyamg package is installed, it is used: this greatly speeds up computation.
fit(X[, y])
Perform spectral clustering from features, or affinity matrix.
fit_predict(X[, y])
Perform spectral clustering from features, or affinity matrix, and return cluster labels.
get_params([deep])
Get parameters for this estimator.
set_params(**params)
Set the parameters of this estimator.
Perform spectral clustering from features, or affinity matrix.
Training instances to cluster, or similarities / affinities between instances if affinity='precomputed'. If a sparse matrix is provided in a format other than csr_matrix, csc_matrix, or coo_matrix, it will be converted into a sparse csr_matrix.
Not used, present here for API consistency by convention.
Perform spectral clustering from features, or affinity matrix, and return cluster labels.
Training instances to cluster, or similarities / affinities between instances if affinity='precomputed'. If a sparse matrix is provided in a format other than csr_matrix, csc_matrix, or coo_matrix, it will be converted into a sparse csr_matrix.
Not used, present here for API consistency by convention.
Cluster 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.
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.
Comparing different clustering algorithms on toy datasets


Perform spectral clustering from features, or affinity matrix.
Training instances to cluster, or similarities / affinities between instances if affinity='precomputed'. If a sparse matrix is provided in a format other than csr_matrix, csc_matrix, or coo_matrix, it will be converted into a sparse csr_matrix.
Not used, present here for API consistency by convention.


Perform spectral clustering from features, or affinity matrix, and return cluster labels.
Training instances to cluster, or similarities / affinities between instances if affinity='precomputed'. If a sparse matrix is provided in a format other than csr_matrix, csc_matrix, or coo_matrix, it will be converted into a sparse csr_matrix.
Not used, present here for API consistency by convention.
Cluster labels.


Spectral Co-Clustering algorithm (Dhillon, 2001).
Clusters rows and columns of an array X to solve the relaxed normalized cut of the bipartite graph created from X as follows: the edge between row vertex i and column vertex j has weight X[i, j].
The resulting bicluster structure is block-diagonal, since each row and each column belongs to exactly one bicluster.
Supports sparse matrices, as long as they are nonnegative.
Read more in the User Guide.
The number of biclusters to find.
Selects the algorithm for finding singular vectors. May be ‘randomized’ or ‘arpack’. If ‘randomized’, use sklearn.utils.extmath.randomized_svd, which may be faster for large matrices. If ‘arpack’, use scipy.sparse.linalg.svds, which is more accurate, but possibly slower in some cases.
Number of vectors to use in calculating the SVD. Corresponds to ncv when svd_method=arpack and n_oversamples when svd_method is ‘randomized`.
Whether to use mini-batch k-means, which is faster but may get different results.
Method for initialization of k-means algorithm; defaults to ‘k-means++’.
Number of random initializations that are tried with the k-means algorithm.
If mini-batch k-means is used, the best initialization is chosen and the algorithm runs once. Otherwise, the algorithm is run for each initialization and the best solution chosen.
The number of jobs to use for the computation. This works by breaking down the pairwise matrix into n_jobs even slices and computing them in parallel.
None means 1 unless in a joblib.parallel_backend context. -1 means using all processors. See Glossary for more details.
Deprecated since version 0.23: n_jobs was deprecated in version 0.23 and will be removed in 1.0 (renaming of 0.25).
Used for randomizing the singular value decomposition and the k-means initialization. Use an int to make the randomness deterministic. See Glossary.
Results of the clustering. rows[i, r] is True if cluster i contains row r. Available only after calling fit.
Results of the clustering, like rows.
The bicluster label of each row.
The bicluster label of each column.
fit(X[, y])
Creates a biclustering for X.
get_indices(i)
Row and column indices of the i’th bicluster.
get_params([deep])
Get parameters for this estimator.
get_shape(i)
Shape of the i’th bicluster.
get_submatrix(i, data)
Return the submatrix corresponding to bicluster i.
set_params(**params)
Set the parameters of this estimator.
Convenient way to get row and column indicators together.
Returns the rows_ and columns_ members.
Creates a biclustering for X.
Row and column indices of the i’th bicluster.
Only works if rows_ and columns_ attributes exist.
The index of the cluster.
Indices of rows in the dataset that belong to the bicluster.
Indices of columns in the dataset that belong to the bicluster.
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.
Shape of the i’th bicluster.
The index of the cluster.
Number of rows in the bicluster.
Number of columns in the bicluster.
Return the submatrix corresponding to bicluster i.
The index of the cluster.
The data.
The submatrix corresponding to bicluster i.
Works with sparse matrices. Only works if rows_ and columns_ attributes exist.
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.


Spectral Co-Clustering algorithm (Dhillon, 2001).
Clusters rows and columns of an array X to solve the relaxed normalized cut of the bipartite graph created from X as follows: the edge between row vertex i and column vertex j has weight X[i, j].
The resulting bicluster structure is block-diagonal, since each row and each column belongs to exactly one bicluster.
Supports sparse matrices, as long as they are nonnegative.
Read more in the User Guide.
The number of biclusters to find.
Selects the algorithm for finding singular vectors. May be ‘randomized’ or ‘arpack’. If ‘randomized’, use sklearn.utils.extmath.randomized_svd, which may be faster for large matrices. If ‘arpack’, use scipy.sparse.linalg.svds, which is more accurate, but possibly slower in some cases.
Number of vectors to use in calculating the SVD. Corresponds to ncv when svd_method=arpack and n_oversamples when svd_method is ‘randomized`.
Whether to use mini-batch k-means, which is faster but may get different results.
Method for initialization of k-means algorithm; defaults to ‘k-means++’.
Number of random initializations that are tried with the k-means algorithm.
If mini-batch k-means is used, the best initialization is chosen and the algorithm runs once. Otherwise, the algorithm is run for each initialization and the best solution chosen.
The number of jobs to use for the computation. This works by breaking down the pairwise matrix into n_jobs even slices and computing them in parallel.
None means 1 unless in a joblib.parallel_backend context. -1 means using all processors. See Glossary for more details.
Deprecated since version 0.23: n_jobs was deprecated in version 0.23 and will be removed in 1.0 (renaming of 0.25).
Used for randomizing the singular value decomposition and the k-means initialization. Use an int to make the randomness deterministic. See Glossary.
Results of the clustering. rows[i, r] is True if cluster i contains row r. Available only after calling fit.
Results of the clustering, like rows.
The bicluster label of each row.
The bicluster label of each column.
fit(X[, y])
Creates a biclustering for X.
get_indices(i)
Row and column indices of the i’th bicluster.
get_params([deep])
Get parameters for this estimator.
get_shape(i)
Shape of the i’th bicluster.
get_submatrix(i, data)
Return the submatrix corresponding to bicluster i.
set_params(**params)
Set the parameters of this estimator.
Convenient way to get row and column indicators together.
Returns the rows_ and columns_ members.
Creates a biclustering for X.
Row and column indices of the i’th bicluster.
Only works if rows_ and columns_ attributes exist.
The index of the cluster.
Indices of rows in the dataset that belong to the bicluster.
Indices of columns in the dataset that belong to the bicluster.
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.
Shape of the i’th bicluster.
The index of the cluster.
Number of rows in the bicluster.
Number of columns in the bicluster.
Return the submatrix corresponding to bicluster i.
The index of the cluster.
The data.
The submatrix corresponding to bicluster i.
Works with sparse matrices. Only works if rows_ and columns_ attributes exist.
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.
A demo of the Spectral Co-Clustering algorithm
Biclustering documents with the Spectral Co-clustering algorithm


Apply clustering to a projection of the normalized Laplacian.
In practice Spectral Clustering is very useful when the structure of the individual clusters is highly non-convex or more generally when a measure of the center and spread of the cluster is not a suitable description of the complete cluster. For instance, when clusters are nested circles on the 2D plane.
If affinity is the adjacency matrix of a graph, this method can be used to find normalized graph cuts.
Read more in the User Guide.
The affinity matrix describing the relationship of the samples to embed. Must be symmetric.
Number of clusters to extract.
Number of eigen vectors to use for the spectral embedding
The eigenvalue decomposition strategy to use. AMG requires pyamg to be installed. It can be faster on very large, sparse problems, but may also lead to instabilities. If None, then 'arpack' is used.
A pseudo random number generator used for the initialization of the lobpcg eigen vectors decomposition when eigen_solver == ‘amg’ and by the K-Means initialization. Use an int to make the randomness deterministic. See Glossary.
Number of time the k-means algorithm will be run with different centroid seeds. The final results will be the best output of n_init consecutive runs in terms of inertia.
Stopping criterion for eigendecomposition of the Laplacian matrix when using arpack eigen_solver.
The strategy to use to assign labels in the embedding space. There are two ways to assign labels after the laplacian embedding. k-means can be applied and is a popular choice. But it can also be sensitive to initialization. Discretization is another approach which is less sensitive to random initialization. See the ‘Multiclass spectral clustering’ paper referenced below for more details on the discretization approach.
Verbosity mode.
New in version 0.24.
The labels of the clusters.
The graph should contain only one connect component, elsewhere the results make little sense.
This algorithm solves the normalized cut for k=2: it is a normalized spectral clustering.


Ward clustering based on a Feature matrix.
Recursively merges the pair of clusters that minimally increases within-cluster variance.
The inertia matrix uses a Heapq-based representation.
This is the structured version, that takes into account some topological structure between samples.
Read more in the User Guide.
feature matrix representing n_samples samples to be clustered
connectivity matrix. Defines for each sample the neighboring samples following a given structure of the data. The matrix is assumed to be symmetric and only the upper triangular half is used. Default is None, i.e, the Ward algorithm is unstructured.
Stop early the construction of the tree at n_clusters. This is useful to decrease computation time if the number of clusters is not small compared to the number of samples. In this case, the complete tree is not computed, thus the ‘children’ output is of limited use, and the ‘parents’ output should rather be used. This option is valid only when specifying a connectivity matrix.
If True, return the distance between the clusters.
The children of each non-leaf node. Values less than n_samples correspond to leaves of the tree which are the original samples. A node i greater than or equal to n_samples is a non-leaf node and has children children_[i - n_samples]. Alternatively at the i-th iteration, children[i][0] and children[i][1] are merged to form node n_samples + i
The number of connected components in the graph.
The number of leaves in the tree
The parent of each node. Only returned when a connectivity matrix is specified, elsewhere ‘None’ is returned.
Only returned if return_distance is set to True (for compatibility). The distances between the centers of the nodes. distances[i] corresponds to a weighted euclidean distance between the nodes children[i, 1] and children[i, 2]. If the nodes refer to leaves of the tree, then distances[i] is their unweighted euclidean distance. Distances are updated in the following way (from scipy.hierarchy.linkage):
The new entry \(d(u,v)\) is computed as follows,
where \(u\) is the newly joined cluster consisting of clusters \(s\) and \(t\), \(v\) is an unused cluster in the forest, \(T=|v|+|s|+|t|\), and \(|*|\) is the cardinality of its argument. This is also known as the incremental algorithm.


Applies transformers to columns of an array or pandas DataFrame.
This estimator allows different columns or column subsets of the input to be transformed separately and the features generated by each transformer will be concatenated to form a single feature space. This is useful for heterogeneous or columnar data, to combine several feature extraction mechanisms or transformations into a single transformer.
Read more in the User Guide.
New in version 0.20.
List of (name, transformer, columns) tuples specifying the transformer objects to be applied to subsets of the data.
Like in Pipeline and FeatureUnion, this allows the transformer and its parameters to be set using set_params and searched in grid search.
Estimator must support fit and transform. Special-cased strings ‘drop’ and ‘passthrough’ are accepted as well, to indicate to drop the columns or to pass them through untransformed, respectively.
Indexes the data on its second axis. Integers are interpreted as positional columns, while strings can reference DataFrame columns by name. A scalar string or int should be used where transformer expects X to be a 1d array-like (vector), otherwise a 2d array will be passed to the transformer. A callable is passed the input data X and can return any of the above. To select multiple columns by name or dtype, you can use make_column_selector.
By default, only the specified columns in transformers are transformed and combined in the output, and the non-specified columns are dropped. (default of 'drop'). By specifying remainder='passthrough', all remaining columns that were not specified in transformers will be automatically passed through. This subset of columns is concatenated with the output of the transformers. By setting remainder to be an estimator, the remaining non-specified columns will use the remainder estimator. The estimator must support fit and transform. Note that using this feature requires that the DataFrame columns input at fit and transform have identical order.
If the output of the different transformers contains sparse matrices, these will be stacked as a sparse matrix if the overall density is lower than this value. Use sparse_threshold=0 to always return dense. When the transformed output consists of all dense data, the stacked result will be dense, and this keyword will be ignored.
Number of jobs to run in parallel. None means 1 unless in a joblib.parallel_backend context. -1 means using all processors. See Glossary for more details.
Multiplicative weights for features per transformer. The output of the transformer is multiplied by these weights. Keys are transformer names, values the weights.
If True, the time elapsed while fitting each transformer will be printed as it is completed.
The collection of fitted transformers as tuples of (name, fitted_transformer, column). fitted_transformer can be an estimator, ‘drop’, or ‘passthrough’. In case there were no columns selected, this will be the unfitted transformer. If there are remaining columns, the final element is a tuple of the form: (‘remainder’, transformer, remaining_columns) corresponding to the remainder parameter. If there are remaining columns, then len(transformers_)==len(transformers)+1, otherwise len(transformers_)==len(transformers).
Access the fitted transformer by name.
Boolean flag indicating whether the output of transform is a sparse matrix or a dense numpy array, which depends on the output of the individual transformers and the sparse_threshold keyword.
See also
Convenience function for combining the outputs of multiple transformer objects applied to column subsets of the original feature space.
Convenience function for selecting columns based on datatype or the columns name with a regex pattern.
The order of the columns in the transformed feature matrix follows the order of how the columns are specified in the transformers list. Columns of the original feature matrix that are not specified are dropped from the resulting transformed feature matrix, unless specified in the passthrough keyword. Those columns specified with passthrough are added at the right to the output of the transformers.
fit(X[, y])
Fit all transformers using X.
fit_transform(X[, y])
Fit all transformers, transform the data and concatenate results.
get_feature_names()
Get feature names from all transformers.
get_params([deep])
Get parameters for this estimator.
set_params(**kwargs)
Set the parameters of this estimator.
transform(X)
Transform X separately by each transformer, concatenate results.
Fit all transformers using X.
Input data, of which specified subsets are used to fit the transformers.
Targets for supervised learning.
This estimator
Fit all transformers, transform the data and concatenate results.
Input data, of which specified subsets are used to fit the transformers.
Targets for supervised learning.
hstack of results of transformers. sum_n_components is the sum of n_components (output dimension) over transformers. If any result is a sparse matrix, everything will be converted to sparse matrices.
Get feature names from all transformers.
Names of the features produced by transform.
Get parameters for this estimator.
Returns the parameters given in the constructor as well as the estimators contained within the transformers of the ColumnTransformer.
If True, will return the parameters for this estimator and contained subobjects that are estimators.
Parameter names mapped to their values.
Access the fitted transformer by name.
Read-only attribute to access any transformer by given name. Keys are transformer names and values are the fitted transformer objects.
Set the parameters of this estimator.
Valid parameter keys can be listed with get_params(). Note that you can directly set the parameters of the estimators contained in transformers of ColumnTransformer.
Transform X separately by each transformer, concatenate results.
The data to be transformed by subset.
hstack of results of transformers. sum_n_components is the sum of n_components (output dimension) over transformers. If any result is a sparse matrix, everything will be converted to sparse matrices.


Applies transformers to columns of an array or pandas DataFrame.
This estimator allows different columns or column subsets of the input to be transformed separately and the features generated by each transformer will be concatenated to form a single feature space. This is useful for heterogeneous or columnar data, to combine several feature extraction mechanisms or transformations into a single transformer.
Read more in the User Guide.
New in version 0.20.
List of (name, transformer, columns) tuples specifying the transformer objects to be applied to subsets of the data.
Like in Pipeline and FeatureUnion, this allows the transformer and its parameters to be set using set_params and searched in grid search.
Estimator must support fit and transform. Special-cased strings ‘drop’ and ‘passthrough’ are accepted as well, to indicate to drop the columns or to pass them through untransformed, respectively.
Indexes the data on its second axis. Integers are interpreted as positional columns, while strings can reference DataFrame columns by name. A scalar string or int should be used where transformer expects X to be a 1d array-like (vector), otherwise a 2d array will be passed to the transformer. A callable is passed the input data X and can return any of the above. To select multiple columns by name or dtype, you can use make_column_selector.
By default, only the specified columns in transformers are transformed and combined in the output, and the non-specified columns are dropped. (default of 'drop'). By specifying remainder='passthrough', all remaining columns that were not specified in transformers will be automatically passed through. This subset of columns is concatenated with the output of the transformers. By setting remainder to be an estimator, the remaining non-specified columns will use the remainder estimator. The estimator must support fit and transform. Note that using this feature requires that the DataFrame columns input at fit and transform have identical order.
If the output of the different transformers contains sparse matrices, these will be stacked as a sparse matrix if the overall density is lower than this value. Use sparse_threshold=0 to always return dense. When the transformed output consists of all dense data, the stacked result will be dense, and this keyword will be ignored.
Number of jobs to run in parallel. None means 1 unless in a joblib.parallel_backend context. -1 means using all processors. See Glossary for more details.
Multiplicative weights for features per transformer. The output of the transformer is multiplied by these weights. Keys are transformer names, values the weights.
If True, the time elapsed while fitting each transformer will be printed as it is completed.
The collection of fitted transformers as tuples of (name, fitted_transformer, column). fitted_transformer can be an estimator, ‘drop’, or ‘passthrough’. In case there were no columns selected, this will be the unfitted transformer. If there are remaining columns, the final element is a tuple of the form: (‘remainder’, transformer, remaining_columns) corresponding to the remainder parameter. If there are remaining columns, then len(transformers_)==len(transformers)+1, otherwise len(transformers_)==len(transformers).
Access the fitted transformer by name.
Boolean flag indicating whether the output of transform is a sparse matrix or a dense numpy array, which depends on the output of the individual transformers and the sparse_threshold keyword.
See also
Convenience function for combining the outputs of multiple transformer objects applied to column subsets of the original feature space.
Convenience function for selecting columns based on datatype or the columns name with a regex pattern.
The order of the columns in the transformed feature matrix follows the order of how the columns are specified in the transformers list. Columns of the original feature matrix that are not specified are dropped from the resulting transformed feature matrix, unless specified in the passthrough keyword. Those columns specified with passthrough are added at the right to the output of the transformers.
fit(X[, y])
Fit all transformers using X.
fit_transform(X[, y])
Fit all transformers, transform the data and concatenate results.
get_feature_names()
Get feature names from all transformers.
get_params([deep])
Get parameters for this estimator.
set_params(**kwargs)
Set the parameters of this estimator.
transform(X)
Transform X separately by each transformer, concatenate results.
Fit all transformers using X.
Input data, of which specified subsets are used to fit the transformers.
Targets for supervised learning.
This estimator
Fit all transformers, transform the data and concatenate results.
Input data, of which specified subsets are used to fit the transformers.
Targets for supervised learning.
hstack of results of transformers. sum_n_components is the sum of n_components (output dimension) over transformers. If any result is a sparse matrix, everything will be converted to sparse matrices.
Get feature names from all transformers.
Names of the features produced by transform.
Get parameters for this estimator.
Returns the parameters given in the constructor as well as the estimators contained within the transformers of the ColumnTransformer.
If True, will return the parameters for this estimator and contained subobjects that are estimators.
Parameter names mapped to their values.
Access the fitted transformer by name.
Read-only attribute to access any transformer by given name. Keys are transformer names and values are the fitted transformer objects.
Set the parameters of this estimator.
Valid parameter keys can be listed with get_params(). Note that you can directly set the parameters of the estimators contained in transformers of ColumnTransformer.
Transform X separately by each transformer, concatenate results.
The data to be transformed by subset.
hstack of results of transformers. sum_n_components is the sum of n_components (output dimension) over transformers. If any result is a sparse matrix, everything will be converted to sparse matrices.
Poisson regression and non-normal loss
Tweedie regression on insurance claims
Permutation Importance vs Random Forest Feature Importance (MDI)
Column Transformer with Mixed Types
Column Transformer with Heterogeneous Data Sources


Fit all transformers using X.
Input data, of which specified subsets are used to fit the transformers.
Targets for supervised learning.
This estimator


Fit all transformers, transform the data and concatenate results.
Input data, of which specified subsets are used to fit the transformers.
Targets for supervised learning.
hstack of results of transformers. sum_n_components is the sum of n_components (output dimension) over transformers. If any result is a sparse matrix, everything will be converted to sparse matrices.


Get feature names from all transformers.
Names of the features produced by transform.


Get parameters for this estimator.
Returns the parameters given in the constructor as well as the estimators contained within the transformers of the ColumnTransformer.
If True, will return the parameters for this estimator and contained subobjects that are estimators.
Parameter names mapped to their values.


Access the fitted transformer by name.
Read-only attribute to access any transformer by given name. Keys are transformer names and values are the fitted transformer objects.


Set the parameters of this estimator.
Valid parameter keys can be listed with get_params(). Note that you can directly set the parameters of the estimators contained in transformers of ColumnTransformer.


Transform X separately by each transformer, concatenate results.
The data to be transformed by subset.
hstack of results of transformers. sum_n_components is the sum of n_components (output dimension) over transformers. If any result is a sparse matrix, everything will be converted to sparse matrices.


Create a callable to select columns to be used with ColumnTransformer.
make_column_selector can select columns based on datatype or the columns name with a regex. When using multiple selection criteria, all criteria must match for a column to be selected.
Name of columns containing this regex pattern will be included. If None, column selection will not be selected based on pattern.
A selection of dtypes to include. For more details, see pandas.DataFrame.select_dtypes.
A selection of dtypes to exclude. For more details, see pandas.DataFrame.select_dtypes.
Callable for column selection to be used by a ColumnTransformer.
See also
Class that allows combining the outputs of multiple transformer objects used on column subsets of the data into a single feature space.


Construct a ColumnTransformer from the given transformers.
This is a shorthand for the ColumnTransformer constructor; it does not require, and does not permit, naming the transformers. Instead, they will be given names automatically based on their types. It also does not allow weighting with transformer_weights.
Read more in the User Guide.
Tuples of the form (transformer, columns) specifying the transformer objects to be applied to subsets of the data.
Estimator must support fit and transform. Special-cased strings ‘drop’ and ‘passthrough’ are accepted as well, to indicate to drop the columns or to pass them through untransformed, respectively.
Indexes the data on its second axis. Integers are interpreted as positional columns, while strings can reference DataFrame columns by name. A scalar string or int should be used where transformer expects X to be a 1d array-like (vector), otherwise a 2d array will be passed to the transformer. A callable is passed the input data X and can return any of the above. To select multiple columns by name or dtype, you can use make_column_selector.
By default, only the specified columns in transformers are transformed and combined in the output, and the non-specified columns are dropped. (default of 'drop'). By specifying remainder='passthrough', all remaining columns that were not specified in transformers will be automatically passed through. This subset of columns is concatenated with the output of the transformers. By setting remainder to be an estimator, the remaining non-specified columns will use the remainder estimator. The estimator must support fit and transform.
If the transformed output consists of a mix of sparse and dense data, it will be stacked as a sparse matrix if the density is lower than this value. Use sparse_threshold=0 to always return dense. When the transformed output consists of all sparse or all dense data, the stacked result will be sparse or dense, respectively, and this keyword will be ignored.
Number of jobs to run in parallel. None means 1 unless in a joblib.parallel_backend context. -1 means using all processors. See Glossary for more details.
If True, the time elapsed while fitting each transformer will be printed as it is completed.
See also
Class that allows combining the outputs of multiple transformer objects used on column subsets of the data into a single feature space.


Meta-estimator to regress on a transformed target.
Useful for applying a non-linear transformation to the target y in regression problems. This transformation can be given as a Transformer such as the QuantileTransformer or as a function and its inverse such as log and exp.
The computation during fit is:
or:
The computation during predict is:
or:
Read more in the User Guide.
New in version 0.20.
Regressor object such as derived from RegressorMixin. This regressor will automatically be cloned each time prior to fitting. If regressor is None, LinearRegression() is created and used.
Estimator object such as derived from TransformerMixin. Cannot be set at the same time as func and inverse_func. If transformer is None as well as func and inverse_func, the transformer will be an identity transformer. Note that the transformer will be cloned during fitting. Also, the transformer is restricting y to be a numpy array.
Function to apply to y before passing to fit. Cannot be set at the same time as transformer. The function needs to return a 2-dimensional array. If func is None, the function used will be the identity function.
Function to apply to the prediction of the regressor. Cannot be set at the same time as transformer as well. The function needs to return a 2-dimensional array. The inverse function is used to return predictions to the same space of the original training labels.
Whether to check that transform followed by inverse_transform or func followed by inverse_func leads to the original targets.
Fitted regressor.
Transformer used in fit and predict.
Internally, the target y is always converted into a 2-dimensional array to be used by scikit-learn transformers. At the time of prediction, the output will be reshaped to a have the same number of dimensions as y.
See examples/compose/plot_transformed_target.py.
fit(X, y, **fit_params)
Fit the model according to the given training data.
get_params([deep])
Get parameters for this estimator.
predict(X)
Predict using the base regressor, applying inverse.
score(X, y[, sample_weight])
Return the coefficient of determination \(R^2\) of the prediction.
set_params(**params)
Set the parameters of this estimator.
Fit the model according to the given training data.
Training vector, where n_samples is the number of samples and n_features is the number of features.
Target values.
Parameters passed to the fit method of the underlying regressor.
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 using the base regressor, applying inverse.
The regressor is used to predict and the inverse_func or inverse_transform is applied before returning the prediction.
Samples.
Predicted values.
Return the coefficient of determination \(R^2\) of the prediction.
The coefficient \(R^2\) is defined as \((1 - \frac{u}{v})\), where \(u\) is the residual sum of squares ((y_true - y_pred)
** 2).sum() and \(v\) is the total sum of squares ((y_true -
y_true.mean()) ** 2).sum(). The best possible score is 1.0 and it can be negative (because the model can be arbitrarily worse). A constant model that always predicts the expected value of y, disregarding the input features, would get a \(R^2\) score of 0.0.
Test samples. For some estimators this may be a precomputed kernel matrix or a list of generic objects instead with shape (n_samples, n_samples_fitted), where n_samples_fitted is the number of samples used in the fitting for the estimator.
True values for X.
Sample weights.
\(R^2\) of self.predict(X) wrt. y.
The \(R^2\) score used when calling score on a regressor uses multioutput='uniform_average' from version 0.23 to keep consistent with default value of r2_score. This influences the score method of all the multioutput regressors (except for MultiOutputRegressor).
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.


Meta-estimator to regress on a transformed target.
Useful for applying a non-linear transformation to the target y in regression problems. This transformation can be given as a Transformer such as the QuantileTransformer or as a function and its inverse such as log and exp.
The computation during fit is:
or:
The computation during predict is:
or:
Read more in the User Guide.
New in version 0.20.
Regressor object such as derived from RegressorMixin. This regressor will automatically be cloned each time prior to fitting. If regressor is None, LinearRegression() is created and used.
Estimator object such as derived from TransformerMixin. Cannot be set at the same time as func and inverse_func. If transformer is None as well as func and inverse_func, the transformer will be an identity transformer. Note that the transformer will be cloned during fitting. Also, the transformer is restricting y to be a numpy array.
Function to apply to y before passing to fit. Cannot be set at the same time as transformer. The function needs to return a 2-dimensional array. If func is None, the function used will be the identity function.
Function to apply to the prediction of the regressor. Cannot be set at the same time as transformer as well. The function needs to return a 2-dimensional array. The inverse function is used to return predictions to the same space of the original training labels.
Whether to check that transform followed by inverse_transform or func followed by inverse_func leads to the original targets.
Fitted regressor.
Transformer used in fit and predict.
Internally, the target y is always converted into a 2-dimensional array to be used by scikit-learn transformers. At the time of prediction, the output will be reshaped to a have the same number of dimensions as y.
See examples/compose/plot_transformed_target.py.
fit(X, y, **fit_params)
Fit the model according to the given training data.
get_params([deep])
Get parameters for this estimator.
predict(X)
Predict using the base regressor, applying inverse.
score(X, y[, sample_weight])
Return the coefficient of determination \(R^2\) of the prediction.
set_params(**params)
Set the parameters of this estimator.
Fit the model according to the given training data.
Training vector, where n_samples is the number of samples and n_features is the number of features.
Target values.
Parameters passed to the fit method of the underlying regressor.
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 using the base regressor, applying inverse.
The regressor is used to predict and the inverse_func or inverse_transform is applied before returning the prediction.
Samples.
Predicted values.
Return the coefficient of determination \(R^2\) of the prediction.
The coefficient \(R^2\) is defined as \((1 - \frac{u}{v})\), where \(u\) is the residual sum of squares ((y_true - y_pred)
** 2).sum() and \(v\) is the total sum of squares ((y_true -
y_true.mean()) ** 2).sum(). The best possible score is 1.0 and it can be negative (because the model can be arbitrarily worse). A constant model that always predicts the expected value of y, disregarding the input features, would get a \(R^2\) score of 0.0.
Test samples. For some estimators this may be a precomputed kernel matrix or a list of generic objects instead with shape (n_samples, n_samples_fitted), where n_samples_fitted is the number of samples used in the fitting for the estimator.
True values for X.
Sample weights.
\(R^2\) of self.predict(X) wrt. y.
The \(R^2\) score used when calling score on a regressor uses multioutput='uniform_average' from version 0.23 to keep consistent with default value of r2_score. This influences the score method of all the multioutput regressors (except for MultiOutputRegressor).
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.
Poisson regression and non-normal loss
Common pitfalls in interpretation of coefficients of linear models
Effect of transforming the targets in regression model


Fit the model according to the given training data.
Training vector, where n_samples is the number of samples and n_features is the number of features.
Target values.
Parameters passed to the fit method of the underlying regressor.


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 using the base regressor, applying inverse.
The regressor is used to predict and the inverse_func or inverse_transform is applied before returning the prediction.
Samples.
Predicted values.


Return the coefficient of determination \(R^2\) of the prediction.
The coefficient \(R^2\) is defined as \((1 - \frac{u}{v})\), where \(u\) is the residual sum of squares ((y_true - y_pred)
** 2).sum() and \(v\) is the total sum of squares ((y_true -
y_true.mean()) ** 2).sum(). The best possible score is 1.0 and it can be negative (because the model can be arbitrarily worse). A constant model that always predicts the expected value of y, disregarding the input features, would get a \(R^2\) score of 0.0.
Test samples. For some estimators this may be a precomputed kernel matrix or a list of generic objects instead with shape (n_samples, n_samples_fitted), where n_samples_fitted is the number of samples used in the fitting for the estimator.
True values for X.
Sample weights.
\(R^2\) of self.predict(X) wrt. y.
The \(R^2\) score used when calling score on a regressor uses multioutput='uniform_average' from version 0.23 to keep consistent with default value of r2_score. This influences the score method of all the multioutput regressors (except for MultiOutputRegressor).


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.


Context manager for global scikit-learn configuration
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.
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.
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()’, but would print ‘SVC(C=1.0, cache_size=200, …)’ with all the non-changed parameters when False. Default is True.
Changed in version 0.23: Default changed from False to True.
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
Set global scikit-learn configuration.
Retrieve current values of the global configuration.
All settings, not just those presently modified, will be returned to their previous values when the context manager is exited. This is not thread-safe.


An object for detecting outliers in a Gaussian distributed dataset.
Read more in the User Guide.
Specify if the estimated precision is stored.
If True, the support of robust location and covariance estimates is computed, and a covariance estimate is recomputed from it, without centering the data. Useful to work with data whose mean is significantly equal to zero but is not exactly zero. If False, the robust location and covariance are directly computed with the FastMCD algorithm without additional treatment.
The proportion of points to be included in the support of the raw MCD estimate. If None, the minimum value of support_fraction will be used within the algorithm: [n_sample + n_features + 1] / 2. Range is (0, 1).
The amount of contamination of the data set, i.e. the proportion of outliers in the data set. Range is (0, 0.5).
Determines the pseudo random number generator for shuffling the data. Pass an int for reproducible results across multiple function calls. See :term: Glossary <random_state>.
Estimated robust location.
Estimated robust covariance matrix.
Estimated pseudo inverse matrix. (stored only if store_precision is True)
A mask of the observations that have been used to compute the robust estimates of location and shape.
Offset used to define the decision function from the raw scores. We have the relation: decision_function = score_samples - offset_. The offset depends on the contamination parameter and is defined in such a way we obtain the expected number of outliers (samples with decision function < 0) in training.
New in version 0.20.
The raw robust estimated location before correction and re-weighting.
The raw robust estimated covariance before correction and re-weighting.
A mask of the observations that have been used to compute the raw robust estimates of location and shape, before correction and re-weighting.
Mahalanobis distances of the training set (on which fit is called) observations.
See also
Outlier detection from covariance estimation may break or not perform well in high-dimensional settings. In particular, one will always take care to work with n_samples > n_features ** 2.
Rousseeuw, P.J., Van Driessen, K. “A fast algorithm for the minimum covariance determinant estimator” Technometrics 41(3), 212 (1999)
correct_covariance(data)
Apply a correction to raw Minimum Covariance Determinant estimates.
decision_function(X)
Compute the decision function of the given observations.
error_norm(comp_cov[, norm, scaling, squared])
Computes the Mean Squared Error between two covariance estimators.
fit(X[, y])
Fit the EllipticEnvelope model.
fit_predict(X[, y])
Perform fit on X and returns labels for X.
get_params([deep])
Get parameters for this estimator.
get_precision()
Getter for the precision matrix.
mahalanobis(X)
Computes the squared Mahalanobis distances of given observations.
predict(X)
Predict the labels (1 inlier, -1 outlier) of X according to the fitted model.
reweight_covariance(data)
Re-weight raw Minimum Covariance Determinant estimates.
score(X, y[, sample_weight])
Returns the mean accuracy on the given test data and labels.
score_samples(X)
Compute the negative Mahalanobis distances.
set_params(**params)
Set the parameters of this estimator.
Apply a correction to raw Minimum Covariance Determinant estimates.
Correction using the empirical correction factor suggested by Rousseeuw and Van Driessen in [RVD].
The data matrix, with p features and n samples. The data set must be the one which was used to compute the raw estimates.
Corrected robust covariance estimate.
A Fast Algorithm for the Minimum Covariance Determinant Estimator, 1999, American Statistical Association and the American Society for Quality, TECHNOMETRICS
Compute the decision function of the given observations.
The data matrix.
Decision function of the samples. It is equal to the shifted Mahalanobis distances. The threshold for being an outlier is 0, which ensures a compatibility with other outlier detection algorithms.
Computes the Mean Squared Error between two covariance estimators. (In the sense of the Frobenius norm).
The covariance to compare with.
The type of norm used to compute the error. Available error types: - ‘frobenius’ (default): sqrt(tr(A^t.A)) - ‘spectral’: sqrt(max(eigenvalues(A^t.A)) where A is the error (comp_cov - self.covariance_).
If True (default), the squared error norm is divided by n_features. If False, the squared error norm is not rescaled.
Whether to compute the squared error norm or the error norm. If True (default), the squared error norm is returned. If False, the error norm is returned.
The Mean Squared Error (in the sense of the Frobenius norm) between self and comp_cov covariance estimators.
Fit the EllipticEnvelope model.
Training data.
Not used, present for API consistency by convention.
Perform fit on X and returns labels for X.
Returns -1 for outliers and 1 for inliers.
Not used, present for API consistency by convention.
1 for inliers, -1 for outliers.
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.
Getter for the precision matrix.
The precision matrix associated to the current covariance object.
Computes the squared Mahalanobis distances of given observations.
The observations, the Mahalanobis distances of the which we compute. Observations are assumed to be drawn from the same distribution than the data used in fit.
Squared Mahalanobis distances of the observations.
Predict the labels (1 inlier, -1 outlier) of X according to the fitted model.
The data matrix.
Returns -1 for anomalies/outliers and +1 for inliers.
Re-weight raw Minimum Covariance Determinant estimates.
Re-weight observations using Rousseeuw’s method (equivalent to deleting outlying observations from the data set before computing location and covariance estimates) described in [RVDriessen].
The data matrix, with p features and n samples. The data set must be the one which was used to compute the raw estimates.
Re-weighted robust location estimate.
Re-weighted robust covariance estimate.
A mask of the observations that have been used to compute the re-weighted robust location and covariance estimates.
A Fast Algorithm for the Minimum Covariance Determinant Estimator, 1999, American Statistical Association and the American Society for Quality, TECHNOMETRICS
Returns 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) w.r.t. y.
Compute the negative Mahalanobis distances.
The data matrix.
Opposite of the Mahalanobis distances.
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.


An object for detecting outliers in a Gaussian distributed dataset.
Read more in the User Guide.
Specify if the estimated precision is stored.
If True, the support of robust location and covariance estimates is computed, and a covariance estimate is recomputed from it, without centering the data. Useful to work with data whose mean is significantly equal to zero but is not exactly zero. If False, the robust location and covariance are directly computed with the FastMCD algorithm without additional treatment.
The proportion of points to be included in the support of the raw MCD estimate. If None, the minimum value of support_fraction will be used within the algorithm: [n_sample + n_features + 1] / 2. Range is (0, 1).
The amount of contamination of the data set, i.e. the proportion of outliers in the data set. Range is (0, 0.5).
Determines the pseudo random number generator for shuffling the data. Pass an int for reproducible results across multiple function calls. See :term: Glossary <random_state>.
Estimated robust location.
Estimated robust covariance matrix.
Estimated pseudo inverse matrix. (stored only if store_precision is True)
A mask of the observations that have been used to compute the robust estimates of location and shape.
Offset used to define the decision function from the raw scores. We have the relation: decision_function = score_samples - offset_. The offset depends on the contamination parameter and is defined in such a way we obtain the expected number of outliers (samples with decision function < 0) in training.
New in version 0.20.
The raw robust estimated location before correction and re-weighting.
The raw robust estimated covariance before correction and re-weighting.
A mask of the observations that have been used to compute the raw robust estimates of location and shape, before correction and re-weighting.
Mahalanobis distances of the training set (on which fit is called) observations.
See also
Outlier detection from covariance estimation may break or not perform well in high-dimensional settings. In particular, one will always take care to work with n_samples > n_features ** 2.
Rousseeuw, P.J., Van Driessen, K. “A fast algorithm for the minimum covariance determinant estimator” Technometrics 41(3), 212 (1999)
correct_covariance(data)
Apply a correction to raw Minimum Covariance Determinant estimates.
decision_function(X)
Compute the decision function of the given observations.
error_norm(comp_cov[, norm, scaling, squared])
Computes the Mean Squared Error between two covariance estimators.
fit(X[, y])
Fit the EllipticEnvelope model.
fit_predict(X[, y])
Perform fit on X and returns labels for X.
get_params([deep])
Get parameters for this estimator.
get_precision()
Getter for the precision matrix.
mahalanobis(X)
Computes the squared Mahalanobis distances of given observations.
predict(X)
Predict the labels (1 inlier, -1 outlier) of X according to the fitted model.
reweight_covariance(data)
Re-weight raw Minimum Covariance Determinant estimates.
score(X, y[, sample_weight])
Returns the mean accuracy on the given test data and labels.
score_samples(X)
Compute the negative Mahalanobis distances.
set_params(**params)
Set the parameters of this estimator.
Apply a correction to raw Minimum Covariance Determinant estimates.
Correction using the empirical correction factor suggested by Rousseeuw and Van Driessen in [RVD].
The data matrix, with p features and n samples. The data set must be the one which was used to compute the raw estimates.
Corrected robust covariance estimate.
A Fast Algorithm for the Minimum Covariance Determinant Estimator, 1999, American Statistical Association and the American Society for Quality, TECHNOMETRICS
Compute the decision function of the given observations.
The data matrix.
Decision function of the samples. It is equal to the shifted Mahalanobis distances. The threshold for being an outlier is 0, which ensures a compatibility with other outlier detection algorithms.
Computes the Mean Squared Error between two covariance estimators. (In the sense of the Frobenius norm).
The covariance to compare with.
The type of norm used to compute the error. Available error types: - ‘frobenius’ (default): sqrt(tr(A^t.A)) - ‘spectral’: sqrt(max(eigenvalues(A^t.A)) where A is the error (comp_cov - self.covariance_).
If True (default), the squared error norm is divided by n_features. If False, the squared error norm is not rescaled.
Whether to compute the squared error norm or the error norm. If True (default), the squared error norm is returned. If False, the error norm is returned.
The Mean Squared Error (in the sense of the Frobenius norm) between self and comp_cov covariance estimators.
Fit the EllipticEnvelope model.
Training data.
Not used, present for API consistency by convention.
Perform fit on X and returns labels for X.
Returns -1 for outliers and 1 for inliers.
Not used, present for API consistency by convention.
1 for inliers, -1 for outliers.
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.
Getter for the precision matrix.
The precision matrix associated to the current covariance object.
Computes the squared Mahalanobis distances of given observations.
The observations, the Mahalanobis distances of the which we compute. Observations are assumed to be drawn from the same distribution than the data used in fit.
Squared Mahalanobis distances of the observations.
Predict the labels (1 inlier, -1 outlier) of X according to the fitted model.
The data matrix.
Returns -1 for anomalies/outliers and +1 for inliers.
Re-weight raw Minimum Covariance Determinant estimates.
Re-weight observations using Rousseeuw’s method (equivalent to deleting outlying observations from the data set before computing location and covariance estimates) described in [RVDriessen].
The data matrix, with p features and n samples. The data set must be the one which was used to compute the raw estimates.
Re-weighted robust location estimate.
Re-weighted robust covariance estimate.
A mask of the observations that have been used to compute the re-weighted robust location and covariance estimates.
A Fast Algorithm for the Minimum Covariance Determinant Estimator, 1999, American Statistical Association and the American Society for Quality, TECHNOMETRICS
Returns 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) w.r.t. y.
Compute the negative Mahalanobis distances.
The data matrix.
Opposite of the Mahalanobis distances.
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.
Outlier detection on a real data set
Comparing anomaly detection algorithms for outlier detection on toy datasets


Apply a correction to raw Minimum Covariance Determinant estimates.
Correction using the empirical correction factor suggested by Rousseeuw and Van Driessen in [RVD].
The data matrix, with p features and n samples. The data set must be the one which was used to compute the raw estimates.
Corrected robust covariance estimate.
A Fast Algorithm for the Minimum Covariance Determinant Estimator, 1999, American Statistical Association and the American Society for Quality, TECHNOMETRICS


Compute the decision function of the given observations.
The data matrix.
Decision function of the samples. It is equal to the shifted Mahalanobis distances. The threshold for being an outlier is 0, which ensures a compatibility with other outlier detection algorithms.


Computes the Mean Squared Error between two covariance estimators. (In the sense of the Frobenius norm).
The covariance to compare with.
The type of norm used to compute the error. Available error types: - ‘frobenius’ (default): sqrt(tr(A^t.A)) - ‘spectral’: sqrt(max(eigenvalues(A^t.A)) where A is the error (comp_cov - self.covariance_).
If True (default), the squared error norm is divided by n_features. If False, the squared error norm is not rescaled.
Whether to compute the squared error norm or the error norm. If True (default), the squared error norm is returned. If False, the error norm is returned.
The Mean Squared Error (in the sense of the Frobenius norm) between self and comp_cov covariance estimators.


Fit the EllipticEnvelope model.
Training data.
Not used, present for API consistency by convention.


Perform fit on X and returns labels for X.
Returns -1 for outliers and 1 for inliers.
Not used, present for API consistency by convention.
1 for inliers, -1 for outliers.


Getter for the precision matrix.
The precision matrix associated to the current covariance object.


Computes the squared Mahalanobis distances of given observations.
The observations, the Mahalanobis distances of the which we compute. Observations are assumed to be drawn from the same distribution than the data used in fit.
Squared Mahalanobis distances of the observations.


Predict the labels (1 inlier, -1 outlier) of X according to the fitted model.
The data matrix.
Returns -1 for anomalies/outliers and +1 for inliers.


Re-weight raw Minimum Covariance Determinant estimates.
Re-weight observations using Rousseeuw’s method (equivalent to deleting outlying observations from the data set before computing location and covariance estimates) described in [RVDriessen].
The data matrix, with p features and n samples. The data set must be the one which was used to compute the raw estimates.
Re-weighted robust location estimate.
Re-weighted robust covariance estimate.
A mask of the observations that have been used to compute the re-weighted robust location and covariance estimates.
A Fast Algorithm for the Minimum Covariance Determinant Estimator, 1999, American Statistical Association and the American Society for Quality, TECHNOMETRICS


Returns 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) w.r.t. y.


Compute the negative Mahalanobis distances.
The data matrix.
Opposite of the Mahalanobis distances.


Maximum likelihood covariance estimator
Read more in the User Guide.
Specifies if the estimated precision is stored.
If True, data are not centered before computation. Useful when working with data whose mean is almost, but not exactly zero. If False (default), data are centered before computation.
Estimated location, i.e. the estimated mean.
Estimated covariance matrix
Estimated pseudo-inverse matrix. (stored only if store_precision is True)
error_norm(comp_cov[, norm, scaling, squared])
Computes the Mean Squared Error between two covariance estimators.
fit(X[, y])
Fits the Maximum Likelihood Estimator covariance model according to the given training data and parameters.
get_params([deep])
Get parameters for this estimator.
get_precision()
Getter for the precision matrix.
mahalanobis(X)
Computes the squared Mahalanobis distances of given observations.
score(X_test[, y])
Computes the log-likelihood of a Gaussian data set with self.covariance_ as an estimator of its covariance matrix.
set_params(**params)
Set the parameters of this estimator.
Computes the Mean Squared Error between two covariance estimators. (In the sense of the Frobenius norm).
The covariance to compare with.
The type of norm used to compute the error. Available error types: - ‘frobenius’ (default): sqrt(tr(A^t.A)) - ‘spectral’: sqrt(max(eigenvalues(A^t.A)) where A is the error (comp_cov - self.covariance_).
If True (default), the squared error norm is divided by n_features. If False, the squared error norm is not rescaled.
Whether to compute the squared error norm or the error norm. If True (default), the squared error norm is returned. If False, the error norm is returned.
The Mean Squared Error (in the sense of the Frobenius norm) between self and comp_cov covariance estimators.
Fits the Maximum Likelihood Estimator covariance model according to the given training data and parameters.
Training data, where n_samples is the number of samples and n_features is the number of features.
Not used, present for API consistency by convention.
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.
Getter for the precision matrix.
The precision matrix associated to the current covariance object.
Computes the squared Mahalanobis distances of given observations.
The observations, the Mahalanobis distances of the which we compute. Observations are assumed to be drawn from the same distribution than the data used in fit.
Squared Mahalanobis distances of the observations.
Computes the log-likelihood of a Gaussian data set with self.covariance_ as an estimator of its covariance matrix.
Test data of which we compute the likelihood, where n_samples is the number of samples and n_features is the number of features. X_test is assumed to be drawn from the same distribution than the data used in fit (including centering).
Not used, present for API consistency by convention.
The likelihood of the data set with self.covariance_ as an estimator of its covariance matrix.
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.


Maximum likelihood covariance estimator
Read more in the User Guide.
Specifies if the estimated precision is stored.
If True, data are not centered before computation. Useful when working with data whose mean is almost, but not exactly zero. If False (default), data are centered before computation.
Estimated location, i.e. the estimated mean.
Estimated covariance matrix
Estimated pseudo-inverse matrix. (stored only if store_precision is True)
error_norm(comp_cov[, norm, scaling, squared])
Computes the Mean Squared Error between two covariance estimators.
fit(X[, y])
Fits the Maximum Likelihood Estimator covariance model according to the given training data and parameters.
get_params([deep])
Get parameters for this estimator.
get_precision()
Getter for the precision matrix.
mahalanobis(X)
Computes the squared Mahalanobis distances of given observations.
score(X_test[, y])
Computes the log-likelihood of a Gaussian data set with self.covariance_ as an estimator of its covariance matrix.
set_params(**params)
Set the parameters of this estimator.
Computes the Mean Squared Error between two covariance estimators. (In the sense of the Frobenius norm).
The covariance to compare with.
The type of norm used to compute the error. Available error types: - ‘frobenius’ (default): sqrt(tr(A^t.A)) - ‘spectral’: sqrt(max(eigenvalues(A^t.A)) where A is the error (comp_cov - self.covariance_).
If True (default), the squared error norm is divided by n_features. If False, the squared error norm is not rescaled.
Whether to compute the squared error norm or the error norm. If True (default), the squared error norm is returned. If False, the error norm is returned.
The Mean Squared Error (in the sense of the Frobenius norm) between self and comp_cov covariance estimators.
Fits the Maximum Likelihood Estimator covariance model according to the given training data and parameters.
Training data, where n_samples is the number of samples and n_features is the number of features.
Not used, present for API consistency by convention.
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.
Getter for the precision matrix.
The precision matrix associated to the current covariance object.
Computes the squared Mahalanobis distances of given observations.
The observations, the Mahalanobis distances of the which we compute. Observations are assumed to be drawn from the same distribution than the data used in fit.
Squared Mahalanobis distances of the observations.
Computes the log-likelihood of a Gaussian data set with self.covariance_ as an estimator of its covariance matrix.
Test data of which we compute the likelihood, where n_samples is the number of samples and n_features is the number of features. X_test is assumed to be drawn from the same distribution than the data used in fit (including centering).
Not used, present for API consistency by convention.
The likelihood of the data set with self.covariance_ as an estimator of its covariance matrix.
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.
Shrinkage covariance estimation: LedoitWolf vs OAS and max-likelihood
Robust covariance estimation and Mahalanobis distances relevance
Robust vs Empirical covariance estimate


Fits the Maximum Likelihood Estimator covariance model according to the given training data and parameters.
Training data, where n_samples is the number of samples and n_features is the number of features.
Not used, present for API consistency by convention.


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.