Theil-Sen Estimator: robust multivariate regression model.
The algorithm calculates least square solutions on subsets with size n_subsamples of the samples in X. Any value of n_subsamples between the number of features and samples leads to an estimator with a compromise between robustness and efficiency. Since the number of least square solutions is “n_samples choose n_subsamples”, it can be extremely large and can therefore be limited with max_subpopulation. If this limit is reached, the subsets are chosen randomly. In a final step, the spatial median (or L1 median) is calculated of all least square solutions.
Read more in the User Guide.
Whether to calculate the intercept for this model. If set to false, no intercept will be used in calculations.
If True, X will be copied; else, it may be overwritten.
Instead of computing with a set of cardinality ‘n choose k’, where n is the number of samples and k is the number of subsamples (at least number of features), consider only a stochastic subpopulation of a given maximal size if ‘n choose k’ is larger than max_subpopulation. For other than small problem sizes this parameter will determine memory usage and runtime if n_subsamples is not changed.
Number of samples to calculate the parameters. This is at least the number of features (plus 1 if fit_intercept=True) and the number of samples as a maximum. A lower number leads to a higher breakdown point and a low efficiency while a high number leads to a low breakdown point and a high efficiency. If None, take the minimum number of subsamples leading to maximal robustness. If n_subsamples is set to n_samples, Theil-Sen is identical to least squares.
Maximum number of iterations for the calculation of spatial median.
Tolerance when calculating spatial median.
A random number generator instance to define the state of the random permutations generator. Pass an int for reproducible output across multiple function calls. See Glossary
Number of CPUs to use during the cross validation. None means 1 unless in a joblib.parallel_backend context. -1 means using all processors. See Glossary for more details.
Verbose mode when fitting the model.
Coefficients of the regression model (median of distribution).
Estimated intercept of regression model.
Approximated breakdown point.
Number of iterations needed for the spatial median.
Number of combinations taken into account from ‘n choose k’, where n is the number of samples and k is the number of subsamples.
fit(X, y)
Fit linear model.
get_params([deep])
Get parameters for this estimator.
predict(X)
Predict using the linear model.
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 linear model.
Training data.
Target values.
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 linear model.
Samples.
Returns 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.
Theil-Sen Regression
Robust linear estimator fitting


Fit linear model.
Training data.
Target values.


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 linear model.
Samples.
Returns 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.


Generalized Linear Model with a Tweedie distribution.
This estimator can be used to model different GLMs depending on the power parameter, which determines the underlying distribution.
Read more in the User Guide.
New in version 0.23.
The power determines the underlying target distribution according to the following table:
Power
Distribution
0
Normal
1
Poisson
(1,2)
Compound Poisson Gamma
2
Gamma
3
Inverse Gaussian
For 0 < power < 1, no distribution exists.
Constant that multiplies the penalty term and thus determines the regularization strength. alpha = 0 is equivalent to unpenalized GLMs. In this case, the design matrix X must have full column rank (no collinearities).
The link function of the GLM, i.e. mapping from linear predictor X @ coeff + intercept to prediction y_pred. Option ‘auto’ sets the link depending on the chosen family as follows:
Specifies if a constant (a.k.a. bias or intercept) should be added to the linear predictor (X @ coef + intercept).
The maximal number of iterations for the solver.
Stopping criterion. For the lbfgs solver, the iteration will stop when max{|g_j|, j = 1, ..., d} <= tol where g_j is the j-th component of the gradient (derivative) of the objective function.
If set to True, reuse the solution of the previous call to fit as initialization for coef_ and intercept_ .
For the lbfgs solver set verbose to any positive number for verbosity.
Estimated coefficients for the linear predictor (X @ coef_ +
intercept_) in the GLM.
Intercept (a.k.a. bias) added to linear predictor.
Actual number of iterations used in the solver.
fit(X, y[, sample_weight])
Fit a Generalized Linear Model.
get_params([deep])
Get parameters for this estimator.
predict(X)
Predict using GLM with feature matrix X.
score(X, y[, sample_weight])
Compute D^2, the percentage of deviance explained.
set_params(**params)
Set the parameters of this estimator.
Fit a Generalized Linear Model.
Training data.
Target values.
Sample weights.
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 GLM with feature matrix X.
Samples.
Returns predicted values.
Compute D^2, the percentage of deviance explained.
D^2 is a generalization of the coefficient of determination R^2. R^2 uses squared error and D^2 deviance. Note that those two are equal for family='normal'.
D^2 is defined as \(D^2 = 1-\frac{D(y_{true},y_{pred})}{D_{null}}\), \(D_{null}\) is the null deviance, i.e. the deviance of a model with intercept alone, which corresponds to \(y_{pred} = \bar{y}\). The mean \(\bar{y}\) is averaged by sample_weight. Best possible score is 1.0 and it can be negative (because the model can be arbitrarily worse).
Test samples.
True values of target.
Sample weights.
D^2 of self.predict(X) w.r.t. y.
Set the parameters of this estimator.
The method works on simple estimators as well as on nested objects (such as Pipeline). The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.
Estimator parameters.
Estimator instance.


Generalized Linear Model with a Tweedie distribution.
This estimator can be used to model different GLMs depending on the power parameter, which determines the underlying distribution.
Read more in the User Guide.
New in version 0.23.
The power determines the underlying target distribution according to the following table:
Power
Distribution
0
Normal
1
Poisson
(1,2)
Compound Poisson Gamma
2
Gamma
3
Inverse Gaussian
For 0 < power < 1, no distribution exists.
Constant that multiplies the penalty term and thus determines the regularization strength. alpha = 0 is equivalent to unpenalized GLMs. In this case, the design matrix X must have full column rank (no collinearities).
The link function of the GLM, i.e. mapping from linear predictor X @ coeff + intercept to prediction y_pred. Option ‘auto’ sets the link depending on the chosen family as follows:
Specifies if a constant (a.k.a. bias or intercept) should be added to the linear predictor (X @ coef + intercept).
The maximal number of iterations for the solver.
Stopping criterion. For the lbfgs solver, the iteration will stop when max{|g_j|, j = 1, ..., d} <= tol where g_j is the j-th component of the gradient (derivative) of the objective function.
If set to True, reuse the solution of the previous call to fit as initialization for coef_ and intercept_ .
For the lbfgs solver set verbose to any positive number for verbosity.
Estimated coefficients for the linear predictor (X @ coef_ +
intercept_) in the GLM.
Intercept (a.k.a. bias) added to linear predictor.
Actual number of iterations used in the solver.
fit(X, y[, sample_weight])
Fit a Generalized Linear Model.
get_params([deep])
Get parameters for this estimator.
predict(X)
Predict using GLM with feature matrix X.
score(X, y[, sample_weight])
Compute D^2, the percentage of deviance explained.
set_params(**params)
Set the parameters of this estimator.
Fit a Generalized Linear Model.
Training data.
Target values.
Sample weights.
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 GLM with feature matrix X.
Samples.
Returns predicted values.
Compute D^2, the percentage of deviance explained.
D^2 is a generalization of the coefficient of determination R^2. R^2 uses squared error and D^2 deviance. Note that those two are equal for family='normal'.
D^2 is defined as \(D^2 = 1-\frac{D(y_{true},y_{pred})}{D_{null}}\), \(D_{null}\) is the null deviance, i.e. the deviance of a model with intercept alone, which corresponds to \(y_{pred} = \bar{y}\). The mean \(\bar{y}\) is averaged by sample_weight. Best possible score is 1.0 and it can be negative (because the model can be arbitrarily worse).
Test samples.
True values of target.
Sample weights.
D^2 of self.predict(X) w.r.t. y.
Set the parameters of this estimator.
The method works on simple estimators as well as on nested objects (such as Pipeline). The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.
Estimator parameters.
Estimator instance.
Release Highlights for scikit-learn 0.23
Tweedie regression on insurance claims


Fit a Generalized Linear Model.
Training data.
Target values.
Sample weights.


Predict using GLM with feature matrix X.
Samples.
Returns predicted values.


Compute D^2, the percentage of deviance explained.
D^2 is a generalization of the coefficient of determination R^2. R^2 uses squared error and D^2 deviance. Note that those two are equal for family='normal'.
D^2 is defined as \(D^2 = 1-\frac{D(y_{true},y_{pred})}{D_{null}}\), \(D_{null}\) is the null deviance, i.e. the deviance of a model with intercept alone, which corresponds to \(y_{pred} = \bar{y}\). The mean \(\bar{y}\) is averaged by sample_weight. Best possible score is 1.0 and it can be negative (because the model can be arbitrarily worse).
Test samples.
True values of target.
Sample weights.
D^2 of self.predict(X) w.r.t. y.


Isomap Embedding
Non-linear dimensionality reduction through Isometric Mapping
Read more in the User Guide.
number of neighbors to consider for each point.
number of coordinates for the manifold
‘auto’ : Attempt to choose the most efficient solver for the given problem.
‘arpack’ : Use Arnoldi decomposition to find the eigenvalues and eigenvectors.
‘dense’ : Use a direct solver (i.e. LAPACK) for the eigenvalue decomposition.
Convergence tolerance passed to arpack or lobpcg. not used if eigen_solver == ‘dense’.
Maximum number of iterations for the arpack solver. not used if eigen_solver == ‘dense’.
Method to use in finding shortest path.
‘auto’ : attempt to choose the best algorithm automatically.
‘FW’ : Floyd-Warshall algorithm.
‘D’ : Dijkstra’s algorithm.
Algorithm to use for nearest neighbors search, passed to neighbors.NearestNeighbors instance.
The number of parallel jobs to run. None means 1 unless in a joblib.parallel_backend context. -1 means using all processors. See Glossary for more details.
The metric to use when calculating distance between instances in a feature array. If metric is a string or callable, it must be one of the options allowed by sklearn.metrics.pairwise_distances for its metric parameter. If metric is “precomputed”, X is assumed to be a distance matrix and must be square. X may be a Glossary.
New in version 0.22.
Parameter for the Minkowski metric from sklearn.metrics.pairwise.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.
New in version 0.22.
Additional keyword arguments for the metric function.
New in version 0.22.
Stores the embedding vectors.
KernelPCA object used to implement the embedding.
Stores nearest neighbors instance, including BallTree or KDtree if applicable.
Stores the geodesic distance matrix of training data.
Tenenbaum, J.B.; De Silva, V.; & Langford, J.C. A global geometric framework for nonlinear dimensionality reduction. Science 290 (5500)
fit(X[, y])
Compute the embedding vectors for data X
fit_transform(X[, y])
Fit the model from data in X and transform X.
get_params([deep])
Get parameters for this estimator.
reconstruction_error()
Compute the reconstruction error for the embedding.
set_params(**params)
Set the parameters of this estimator.
transform(X)
Transform X.
Compute the embedding vectors for data X
Sample data, shape = (n_samples, n_features), in the form of a numpy array, sparse graph, precomputed tree, or NearestNeighbors object.
Fit the model from data in X and transform X.
Training vector, where n_samples in the number of samples and n_features is the number of features.
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.
Compute the reconstruction error for the embedding.
The cost function of an isomap embedding is
E = frobenius_norm[K(D) - K(D_fit)] / n_samples
Where D is the matrix of distances for the input data X, D_fit is the matrix of distances for the output embedding X_fit, and K is the isomap kernel:
K(D) = -0.5 * (I - 1/n_samples) * D^2 * (I - 1/n_samples)
Set the parameters of this estimator.
The method works on simple estimators as well as on nested objects (such as Pipeline). The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.
Estimator parameters.
Estimator instance.
Transform X.
This is implemented by linking the points X into the graph of geodesic distances of the training data. First the n_neighbors nearest neighbors of X are found in the training data, and from these the shortest geodesic distances from each point in X to each point in the training data are computed in order to construct the kernel. The embedding of X is the projection of this kernel onto the embedding vectors of the training set.
If neighbors_algorithm=’precomputed’, X is assumed to be a distance matrix or a sparse graph of shape (n_queries, n_samples_fit).


Isomap Embedding
Non-linear dimensionality reduction through Isometric Mapping
Read more in the User Guide.
number of neighbors to consider for each point.
number of coordinates for the manifold
‘auto’ : Attempt to choose the most efficient solver for the given problem.
‘arpack’ : Use Arnoldi decomposition to find the eigenvalues and eigenvectors.
‘dense’ : Use a direct solver (i.e. LAPACK) for the eigenvalue decomposition.
Convergence tolerance passed to arpack or lobpcg. not used if eigen_solver == ‘dense’.
Maximum number of iterations for the arpack solver. not used if eigen_solver == ‘dense’.
Method to use in finding shortest path.
‘auto’ : attempt to choose the best algorithm automatically.
‘FW’ : Floyd-Warshall algorithm.
‘D’ : Dijkstra’s algorithm.
Algorithm to use for nearest neighbors search, passed to neighbors.NearestNeighbors instance.
The number of parallel jobs to run. None means 1 unless in a joblib.parallel_backend context. -1 means using all processors. See Glossary for more details.
The metric to use when calculating distance between instances in a feature array. If metric is a string or callable, it must be one of the options allowed by sklearn.metrics.pairwise_distances for its metric parameter. If metric is “precomputed”, X is assumed to be a distance matrix and must be square. X may be a Glossary.
New in version 0.22.
Parameter for the Minkowski metric from sklearn.metrics.pairwise.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.
New in version 0.22.
Additional keyword arguments for the metric function.
New in version 0.22.
Stores the embedding vectors.
KernelPCA object used to implement the embedding.
Stores nearest neighbors instance, including BallTree or KDtree if applicable.
Stores the geodesic distance matrix of training data.
Tenenbaum, J.B.; De Silva, V.; & Langford, J.C. A global geometric framework for nonlinear dimensionality reduction. Science 290 (5500)
fit(X[, y])
Compute the embedding vectors for data X
fit_transform(X[, y])
Fit the model from data in X and transform X.
get_params([deep])
Get parameters for this estimator.
reconstruction_error()
Compute the reconstruction error for the embedding.
set_params(**params)
Set the parameters of this estimator.
transform(X)
Transform X.
Compute the embedding vectors for data X
Sample data, shape = (n_samples, n_features), in the form of a numpy array, sparse graph, precomputed tree, or NearestNeighbors object.
Fit the model from data in X and transform X.
Training vector, where n_samples in the number of samples and n_features is the number of features.
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.
Compute the reconstruction error for the embedding.
The cost function of an isomap embedding is
E = frobenius_norm[K(D) - K(D_fit)] / n_samples
Where D is the matrix of distances for the input data X, D_fit is the matrix of distances for the output embedding X_fit, and K is the isomap kernel:
K(D) = -0.5 * (I - 1/n_samples) * D^2 * (I - 1/n_samples)
Set the parameters of this estimator.
The method works on simple estimators as well as on nested objects (such as Pipeline). The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.
Estimator parameters.
Estimator instance.
Transform X.
This is implemented by linking the points X into the graph of geodesic distances of the training data. First the n_neighbors nearest neighbors of X are found in the training data, and from these the shortest geodesic distances from each point in X to each point in the training data are computed in order to construct the kernel. The embedding of X is the projection of this kernel onto the embedding vectors of the training set.
If neighbors_algorithm=’precomputed’, X is assumed to be a distance matrix or a sparse graph of shape (n_queries, n_samples_fit).
Release Highlights for scikit-learn 0.22
Comparison of Manifold Learning methods
Manifold Learning methods on a severed sphere
Manifold learning on handwritten digits: Locally Linear Embedding, Isomap…


Compute the embedding vectors for data X
Sample data, shape = (n_samples, n_features), in the form of a numpy array, sparse graph, precomputed tree, or NearestNeighbors object.


Fit the model from data in X and transform X.
Training vector, where n_samples in the number of samples and n_features is the number of features.


Compute the reconstruction error for the embedding.
The cost function of an isomap embedding is
E = frobenius_norm[K(D) - K(D_fit)] / n_samples
Where D is the matrix of distances for the input data X, D_fit is the matrix of distances for the output embedding X_fit, and K is the isomap kernel:
K(D) = -0.5 * (I - 1/n_samples) * D^2 * (I - 1/n_samples)


Transform X.
This is implemented by linking the points X into the graph of geodesic distances of the training data. First the n_neighbors nearest neighbors of X are found in the training data, and from these the shortest geodesic distances from each point in X to each point in the training data are computed in order to construct the kernel. The embedding of X is the projection of this kernel onto the embedding vectors of the training set.
If neighbors_algorithm=’precomputed’, X is assumed to be a distance matrix or a sparse graph of shape (n_queries, n_samples_fit).


Locally Linear Embedding
Read more in the User Guide.
number of neighbors to consider for each point.
number of coordinates for the manifold
regularization constant, multiplies the trace of the local covariance matrix of the distances.
auto : algorithm will attempt to choose the best method for input data
For this method, M may be a dense matrix, sparse matrix, or general linear operator. Warning: ARPACK can be unstable for some problems. It is best to try several random seeds in order to check results.
decomposition. For this method, M must be an array or matrix type. This method should be avoided for large problems.
Tolerance for ‘arpack’ method Not used if eigen_solver==’dense’.
maximum number of iterations for the arpack solver. Not used if eigen_solver==’dense’.
reference [1]
n_neighbors > n_components * (1 + (n_components + 1) / 2 see reference [2]
see reference [3]
see reference [4]
Tolerance for Hessian eigenmapping method. Only used if method == 'hessian'
Tolerance for modified LLE method. Only used if method == 'modified'
algorithm to use for nearest neighbors search, passed to neighbors.NearestNeighbors instance
Determines the random number generator when eigen_solver == ‘arpack’. Pass an int for reproducible results across multiple function calls. See :term: Glossary <random_state>.
The number of parallel jobs to run. None means 1 unless in a joblib.parallel_backend context. -1 means using all processors. See Glossary for more details.
Stores the embedding vectors
Reconstruction error associated with embedding_
Stores nearest neighbors instance, including BallTree or KDtree if applicable.
Roweis, S. & Saul, L. Nonlinear dimensionality reduction by locally linear embedding. Science 290:2323 (2000).
Donoho, D. & Grimes, C. Hessian eigenmaps: Locally linear embedding techniques for high-dimensional data. Proc Natl Acad Sci U S A. 100:5591 (2003).
Zhang, Z. & Wang, J. MLLE: Modified Locally Linear Embedding Using Multiple Weights. http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.70.382
Zhang, Z. & Zha, H. Principal manifolds and nonlinear dimensionality reduction via tangent space alignment. Journal of Shanghai Univ. 8:406 (2004)
fit(X[, y])
Compute the embedding vectors for data X
fit_transform(X[, y])
Compute the embedding vectors for data X and transform X.
get_params([deep])
Get parameters for this estimator.
set_params(**params)
Set the parameters of this estimator.
transform(X)
Transform new points into embedding space.
Compute the embedding vectors for data X
training set.
Compute the embedding vectors for data X and transform X.
training set.
Get parameters for this estimator.
If True, will return the parameters for this estimator and contained subobjects that are estimators.
Parameter names mapped to their values.
Set the parameters of this estimator.
The method works on simple estimators as well as on nested objects (such as Pipeline). The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.
Estimator parameters.
Estimator instance.
Transform new points into embedding space.
Because of scaling performed by this method, it is discouraged to use it together with methods that are not scale-invariant (like SVMs)


Locally Linear Embedding
Read more in the User Guide.
number of neighbors to consider for each point.
number of coordinates for the manifold
regularization constant, multiplies the trace of the local covariance matrix of the distances.
auto : algorithm will attempt to choose the best method for input data
For this method, M may be a dense matrix, sparse matrix, or general linear operator. Warning: ARPACK can be unstable for some problems. It is best to try several random seeds in order to check results.
decomposition. For this method, M must be an array or matrix type. This method should be avoided for large problems.
Tolerance for ‘arpack’ method Not used if eigen_solver==’dense’.
maximum number of iterations for the arpack solver. Not used if eigen_solver==’dense’.
reference [1]
n_neighbors > n_components * (1 + (n_components + 1) / 2 see reference [2]
see reference [3]
see reference [4]
Tolerance for Hessian eigenmapping method. Only used if method == 'hessian'
Tolerance for modified LLE method. Only used if method == 'modified'
algorithm to use for nearest neighbors search, passed to neighbors.NearestNeighbors instance
Determines the random number generator when eigen_solver == ‘arpack’. Pass an int for reproducible results across multiple function calls. See :term: Glossary <random_state>.
The number of parallel jobs to run. None means 1 unless in a joblib.parallel_backend context. -1 means using all processors. See Glossary for more details.
Stores the embedding vectors
Reconstruction error associated with embedding_
Stores nearest neighbors instance, including BallTree or KDtree if applicable.
Roweis, S. & Saul, L. Nonlinear dimensionality reduction by locally linear embedding. Science 290:2323 (2000).
Donoho, D. & Grimes, C. Hessian eigenmaps: Locally linear embedding techniques for high-dimensional data. Proc Natl Acad Sci U S A. 100:5591 (2003).
Zhang, Z. & Wang, J. MLLE: Modified Locally Linear Embedding Using Multiple Weights. http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.70.382
Zhang, Z. & Zha, H. Principal manifolds and nonlinear dimensionality reduction via tangent space alignment. Journal of Shanghai Univ. 8:406 (2004)
fit(X[, y])
Compute the embedding vectors for data X
fit_transform(X[, y])
Compute the embedding vectors for data X and transform X.
get_params([deep])
Get parameters for this estimator.
set_params(**params)
Set the parameters of this estimator.
transform(X)
Transform new points into embedding space.
Compute the embedding vectors for data X
training set.
Compute the embedding vectors for data X and transform X.
training set.
Get parameters for this estimator.
If True, will return the parameters for this estimator and contained subobjects that are estimators.
Parameter names mapped to their values.
Set the parameters of this estimator.
The method works on simple estimators as well as on nested objects (such as Pipeline). The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.
Estimator parameters.
Estimator instance.
Transform new points into embedding space.
Because of scaling performed by this method, it is discouraged to use it together with methods that are not scale-invariant (like SVMs)
Visualizing the stock market structure
Comparison of Manifold Learning methods
Manifold Learning methods on a severed sphere
Manifold learning on handwritten digits: Locally Linear Embedding, Isomap…


Compute the embedding vectors for data X
training set.


Compute the embedding vectors for data X and transform X.
training set.


Get parameters for this estimator.
If True, will return the parameters for this estimator and contained subobjects that are estimators.
Parameter names mapped to their values.


Set the parameters of this estimator.
The method works on simple estimators as well as on nested objects (such as Pipeline). The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.
Estimator parameters.
Estimator instance.


Transform new points into embedding space.
Because of scaling performed by this method, it is discouraged to use it together with methods that are not scale-invariant (like SVMs)


Perform a Locally Linear Embedding analysis on the data.
Read more in the User Guide.
Sample data, shape = (n_samples, n_features), in the form of a numpy array or a NearestNeighbors object.
number of neighbors to consider for each point.
number of coordinates for the manifold.
regularization constant, multiplies the trace of the local covariance matrix of the distances.
auto : algorithm will attempt to choose the best method for input data
For this method, M may be a dense matrix, sparse matrix, or general linear operator. Warning: ARPACK can be unstable for some problems. It is best to try several random seeds in order to check results.
decomposition. For this method, M must be an array or matrix type. This method should be avoided for large problems.
Tolerance for ‘arpack’ method Not used if eigen_solver==’dense’.
maximum number of iterations for the arpack solver.
see reference [1]
n_neighbors > n_components * (1 + (n_components + 1) / 2. see reference [2]
see reference [3]
see reference [4]
Tolerance for Hessian eigenmapping method. Only used if method == ‘hessian’
Tolerance for modified LLE method. Only used if method == ‘modified’
Determines the random number generator when solver == ‘arpack’. Pass an int for reproducible results across multiple function calls. See :term: Glossary <random_state>.
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.
Embedding vectors.
Reconstruction error for the embedding vectors. Equivalent to norm(Y - W Y, 'fro')**2, where W are the reconstruction weights.
Roweis, S. & Saul, L. Nonlinear dimensionality reduction by locally linear embedding. Science 290:2323 (2000).
Donoho, D. & Grimes, C. Hessian eigenmaps: Locally linear embedding techniques for high-dimensional data. Proc Natl Acad Sci U S A. 100:5591 (2003).
Zhang, Z. & Wang, J. MLLE: Modified Locally Linear Embedding Using Multiple Weights. http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.70.382
Zhang, Z. & Zha, H. Principal manifolds and nonlinear dimensionality reduction via tangent space alignment. Journal of Shanghai Univ. 8:406 (2004)


Multidimensional scaling.
Read more in the User Guide.
Number of dimensions in which to immerse the dissimilarities.
If True, perform metric MDS; otherwise, perform nonmetric MDS.
Number of times the SMACOF algorithm will be run with different initializations. The final results will be the best output of the runs, determined by the run with the smallest final stress.
Maximum number of iterations of the SMACOF algorithm for a single run.
Level of verbosity.
Relative tolerance with respect to stress at which to declare convergence.
The number of jobs to use for the computation. If multiple initializations are used (n_init), each run of the algorithm is computed in parallel.
None means 1 unless in a joblib.parallel_backend context. -1 means using all processors. See Glossary for more details.
Determines the random number generator used to initialize the centers. Pass an int for reproducible results across multiple function calls. See :term: Glossary <random_state>.
Dissimilarity measure to use:
Pairwise Euclidean distances between points in the dataset.
Pre-computed dissimilarities are passed directly to fit and fit_transform.
Stores the position of the dataset in the embedding space.
The final value of the stress (sum of squared distance of the disparities and the distances for all constrained points).
Pairwise dissimilarities between the points. Symmetric matrix that:
The number of iterations corresponding to the best stress.
“Modern Multidimensional Scaling - Theory and Applications” Borg, I.; Groenen P. Springer Series in Statistics (1997)
“Nonmetric multidimensional scaling: a numerical method” Kruskal, J. Psychometrika, 29 (1964)
“Multidimensional scaling by optimizing goodness of fit to a nonmetric hypothesis” Kruskal, J. Psychometrika, 29, (1964)
fit(X[, y, init])
Computes the position of the points in the embedding space.
fit_transform(X[, y, init])
Fit the data from X, and returns the embedded coordinates.
get_params([deep])
Get parameters for this estimator.
set_params(**params)
Set the parameters of this estimator.
Computes the position of the points in the embedding space.
Input data. If dissimilarity=='precomputed', the input should be the dissimilarity matrix.
Starting configuration of the embedding to initialize the SMACOF algorithm. By default, the algorithm is initialized with a randomly chosen array.
Fit the data from X, and returns the embedded coordinates.
Input data. If dissimilarity=='precomputed', the input should be the dissimilarity matrix.
Starting configuration of the embedding to initialize the SMACOF algorithm. By default, the algorithm is initialized with a randomly chosen array.
Get parameters for this estimator.
If True, will return the parameters for this estimator and contained subobjects that are estimators.
Parameter names mapped to their values.
Set the parameters of this estimator.
The method works on simple estimators as well as on nested objects (such as Pipeline). The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.
Estimator parameters.
Estimator instance.


Multidimensional scaling.
Read more in the User Guide.
Number of dimensions in which to immerse the dissimilarities.
If True, perform metric MDS; otherwise, perform nonmetric MDS.
Number of times the SMACOF algorithm will be run with different initializations. The final results will be the best output of the runs, determined by the run with the smallest final stress.
Maximum number of iterations of the SMACOF algorithm for a single run.
Level of verbosity.
Relative tolerance with respect to stress at which to declare convergence.
The number of jobs to use for the computation. If multiple initializations are used (n_init), each run of the algorithm is computed in parallel.
None means 1 unless in a joblib.parallel_backend context. -1 means using all processors. See Glossary for more details.
Determines the random number generator used to initialize the centers. Pass an int for reproducible results across multiple function calls. See :term: Glossary <random_state>.
Dissimilarity measure to use:
Pairwise Euclidean distances between points in the dataset.
Pre-computed dissimilarities are passed directly to fit and fit_transform.
Stores the position of the dataset in the embedding space.
The final value of the stress (sum of squared distance of the disparities and the distances for all constrained points).
Pairwise dissimilarities between the points. Symmetric matrix that:
The number of iterations corresponding to the best stress.
“Modern Multidimensional Scaling - Theory and Applications” Borg, I.; Groenen P. Springer Series in Statistics (1997)
“Nonmetric multidimensional scaling: a numerical method” Kruskal, J. Psychometrika, 29 (1964)
“Multidimensional scaling by optimizing goodness of fit to a nonmetric hypothesis” Kruskal, J. Psychometrika, 29, (1964)
fit(X[, y, init])
Computes the position of the points in the embedding space.
fit_transform(X[, y, init])
Fit the data from X, and returns the embedded coordinates.
get_params([deep])
Get parameters for this estimator.
set_params(**params)
Set the parameters of this estimator.
Computes the position of the points in the embedding space.
Input data. If dissimilarity=='precomputed', the input should be the dissimilarity matrix.
Starting configuration of the embedding to initialize the SMACOF algorithm. By default, the algorithm is initialized with a randomly chosen array.
Fit the data from X, and returns the embedded coordinates.
Input data. If dissimilarity=='precomputed', the input should be the dissimilarity matrix.
Starting configuration of the embedding to initialize the SMACOF algorithm. By default, the algorithm is initialized with a randomly chosen array.
Get parameters for this estimator.
If True, will return the parameters for this estimator and contained subobjects that are estimators.
Parameter names mapped to their values.
Set the parameters of this estimator.
The method works on simple estimators as well as on nested objects (such as Pipeline). The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.
Estimator parameters.
Estimator instance.
Comparison of Manifold Learning methods
Multi-dimensional scaling
Manifold Learning methods on a severed sphere
Manifold learning on handwritten digits: Locally Linear Embedding, Isomap…


Computes the position of the points in the embedding space.
Input data. If dissimilarity=='precomputed', the input should be the dissimilarity matrix.
Starting configuration of the embedding to initialize the SMACOF algorithm. By default, the algorithm is initialized with a randomly chosen array.


Fit the data from X, and returns the embedded coordinates.
Input data. If dissimilarity=='precomputed', the input should be the dissimilarity matrix.
Starting configuration of the embedding to initialize the SMACOF algorithm. By default, the algorithm is initialized with a randomly chosen array.


Computes multidimensional scaling using the SMACOF algorithm.
The SMACOF (Scaling by MAjorizing a COmplicated Function) algorithm is a multidimensional scaling algorithm which minimizes an objective function (the stress) using a majorization technique. Stress majorization, also known as the Guttman Transform, guarantees a monotone convergence of stress, and is more powerful than traditional techniques such as gradient descent.
The SMACOF algorithm for metric MDS can summarized by the following steps:
The nonmetric algorithm adds a monotonic regression step before computing the stress.
Pairwise dissimilarities between the points. Must be symmetric.
Compute metric or nonmetric SMACOF algorithm.
Number of dimensions in which to immerse the dissimilarities. If an init array is provided, this option is overridden and the shape of init is used to determine the dimensionality of the embedding space.
Starting configuration of the embedding to initialize the algorithm. By default, the algorithm is initialized with a randomly chosen array.
Number of times the SMACOF algorithm will be run with different initializations. The final results will be the best output of the runs, determined by the run with the smallest final stress. If init is provided, this option is overridden and a single run is performed.
The number of jobs to use for the computation. If multiple initializations are used (n_init), each run of the algorithm is computed in parallel.
None means 1 unless in a joblib.parallel_backend context. -1 means using all processors. See Glossary for more details.
Maximum number of iterations of the SMACOF algorithm for a single run.
Level of verbosity.
Relative tolerance with respect to stress at which to declare convergence.
Determines the random number generator used to initialize the centers. Pass an int for reproducible results across multiple function calls. See :term: Glossary <random_state>.
Whether or not to return the number of iterations.
Coordinates of the points in a n_components-space.
The final value of the stress (sum of squared distance of the disparities and the distances for all constrained points).
The number of iterations corresponding to the best stress. Returned only if return_n_iter is set to True.
“Modern Multidimensional Scaling - Theory and Applications” Borg, I.; Groenen P. Springer Series in Statistics (1997)
“Nonmetric multidimensional scaling: a numerical method” Kruskal, J. Psychometrika, 29 (1964)
“Multidimensional scaling by optimizing goodness of fit to a nonmetric hypothesis” Kruskal, J. Psychometrika, 29, (1964)


Spectral embedding for non-linear dimensionality reduction.
Forms an affinity matrix given by the specified function and applies spectral decomposition to the corresponding graph laplacian. The resulting transformation is given by the value of the eigenvectors for each data point.
Note : Laplacian Eigenmaps is the actual algorithm implemented here.
Read more in the User Guide.
The dimension of the projected subspace.
Kernel coefficient for rbf kernel. If None, gamma will be set to 1/n_features.
Determines the random number generator used for the initialization of the lobpcg eigenvectors when solver == ‘amg’. Pass an int for reproducible results across multiple function calls. See :term: Glossary <random_state>.
The eigenvalue decomposition strategy to use. AMG requires pyamg to be installed. It can be faster on very large, sparse problems. If None, then 'arpack' is used.
Number of nearest neighbors for nearest_neighbors graph building. If None, n_neighbors will be set to max(n_samples/10, 1).
The number of parallel jobs to run. None means 1 unless in a joblib.parallel_backend context. -1 means using all processors. See Glossary for more details.
Spectral embedding of the training matrix.
Affinity_matrix constructed from samples or precomputed.
Number of nearest neighbors effectively used.
fit(X[, y])
Fit the model from data in X.
fit_transform(X[, y])
Fit the model from data in X and transform X.
get_params([deep])
Get parameters for this estimator.
set_params(**params)
Set the parameters of this estimator.
Fit the model from data in X.
Training vector, where n_samples is the number of samples and n_features is the number of features.
If affinity is “precomputed” X : {array-like, sparse matrix}, shape (n_samples, n_samples), Interpret X as precomputed adjacency graph computed from samples.
Returns the instance itself.
Fit the model from data in X and transform X.
Training vector, where n_samples is the number of samples and n_features is the number of features.
If affinity is “precomputed” X : {array-like, sparse matrix} of shape (n_samples, n_samples), Interpret X as precomputed adjacency graph computed from samples.
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 embedding for non-linear dimensionality reduction.
Forms an affinity matrix given by the specified function and applies spectral decomposition to the corresponding graph laplacian. The resulting transformation is given by the value of the eigenvectors for each data point.
Note : Laplacian Eigenmaps is the actual algorithm implemented here.
Read more in the User Guide.
The dimension of the projected subspace.
Kernel coefficient for rbf kernel. If None, gamma will be set to 1/n_features.
Determines the random number generator used for the initialization of the lobpcg eigenvectors when solver == ‘amg’. Pass an int for reproducible results across multiple function calls. See :term: Glossary <random_state>.
The eigenvalue decomposition strategy to use. AMG requires pyamg to be installed. It can be faster on very large, sparse problems. If None, then 'arpack' is used.
Number of nearest neighbors for nearest_neighbors graph building. If None, n_neighbors will be set to max(n_samples/10, 1).
The number of parallel jobs to run. None means 1 unless in a joblib.parallel_backend context. -1 means using all processors. See Glossary for more details.
Spectral embedding of the training matrix.
Affinity_matrix constructed from samples or precomputed.
Number of nearest neighbors effectively used.
fit(X[, y])
Fit the model from data in X.
fit_transform(X[, y])
Fit the model from data in X and transform X.
get_params([deep])
Get parameters for this estimator.
set_params(**params)
Set the parameters of this estimator.
Fit the model from data in X.
Training vector, where n_samples is the number of samples and n_features is the number of features.
If affinity is “precomputed” X : {array-like, sparse matrix}, shape (n_samples, n_samples), Interpret X as precomputed adjacency graph computed from samples.
Returns the instance itself.
Fit the model from data in X and transform X.
Training vector, where n_samples is the number of samples and n_features is the number of features.
If affinity is “precomputed” X : {array-like, sparse matrix} of shape (n_samples, n_samples), Interpret X as precomputed adjacency graph computed from samples.
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.
Various Agglomerative Clustering on a 2D embedding of digits
Comparison of Manifold Learning methods
Manifold Learning methods on a severed sphere
Manifold learning on handwritten digits: Locally Linear Embedding, Isomap…


Fit the model from data in X.
Training vector, where n_samples is the number of samples and n_features is the number of features.
If affinity is “precomputed” X : {array-like, sparse matrix}, shape (n_samples, n_samples), Interpret X as precomputed adjacency graph computed from samples.
Returns the instance itself.


Fit the model from data in X and transform X.
Training vector, where n_samples is the number of samples and n_features is the number of features.
If affinity is “precomputed” X : {array-like, sparse matrix} of shape (n_samples, n_samples), Interpret X as precomputed adjacency graph computed from samples.


Project the sample on the first eigenvectors of the graph Laplacian.
The adjacency matrix is used to compute a normalized graph Laplacian whose spectrum (especially the eigenvectors associated to the smallest eigenvalues) has an interpretation in terms of minimal number of cuts necessary to split the graph into comparably sized components.
This embedding can also ‘work’ even if the adjacency variable is not strictly the adjacency matrix of a graph but more generally an affinity or similarity matrix between samples (for instance the heat kernel of a euclidean distance matrix or a k-NN matrix).
However care must taken to always make the affinity matrix symmetric so that the eigenvector decomposition works as expected.
Note : Laplacian Eigenmaps is the actual algorithm implemented here.
Read more in the User Guide.
The adjacency matrix of the graph to embed.
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.
Determines the random number generator used for the initialization of the lobpcg eigenvectors decomposition when solver == ‘amg’. Pass an int for reproducible results across multiple function calls. See :term: Glossary <random_state>.
Stopping criterion for eigendecomposition of the Laplacian matrix when using arpack eigen_solver.
If True, then compute normalized Laplacian.
Whether to drop the first eigenvector. For spectral embedding, this should be True as the first eigenvector should be constant vector for connected graph, but for spectral clustering, this should be kept as False to retain the first eigenvector.
The reduced samples.
Spectral Embedding (Laplacian Eigenmaps) is most useful when the graph has one connected component. If there graph has many components, the first few eigenvectors will simply uncover the connected components of the graph.


Expresses to what extent the local structure is retained.
The trustworthiness is within [0, 1]. It is defined as
where for each sample i, \(\mathcal{N}_{i}^{k}\) are its k nearest neighbors in the output space, and every sample j is its \(r(i, j)\)-th nearest neighbor in the input space. In other words, any unexpected nearest neighbors in the output space are penalised in proportion to their rank in the input space.
If the metric is ‘precomputed’ X must be a square distance matrix. Otherwise it contains a sample per row.
Embedding of the training data in low-dimensional space.
Number of neighbors k that will be considered.
Which metric to use for computing pairwise distances between samples from the original input space. If metric is ‘precomputed’, X must be a matrix of pairwise distances or squared distances. Otherwise, see the documentation of argument metric in sklearn.pairwise.pairwise_distances for a list of available metrics.
New in version 0.20.
Trustworthiness of the low-dimensional embedding.


t-distributed Stochastic Neighbor Embedding.
t-SNE [1] is a tool to visualize high-dimensional data. It converts similarities between data points to joint probabilities and tries to minimize the Kullback-Leibler divergence between the joint probabilities of the low-dimensional embedding and the high-dimensional data. t-SNE has a cost function that is not convex, i.e. with different initializations we can get different results.
It is highly recommended to use another dimensionality reduction method (e.g. PCA for dense data or TruncatedSVD for sparse data) to reduce the number of dimensions to a reasonable amount (e.g. 50) if the number of features is very high. This will suppress some noise and speed up the computation of pairwise distances between samples. For more tips see Laurens van der Maaten’s FAQ [2].
Read more in the User Guide.
Dimension of the embedded space.
The perplexity is related to the number of nearest neighbors that is used in other manifold learning algorithms. Larger datasets usually require a larger perplexity. Consider selecting a value between 5 and 50. Different values can result in significantly different results.
Controls how tight natural clusters in the original space are in the embedded space and how much space will be between them. For larger values, the space between natural clusters will be larger in the embedded space. Again, the choice of this parameter is not very critical. If the cost function increases during initial optimization, the early exaggeration factor or the learning rate might be too high.
The learning rate for t-SNE is usually in the range [10.0, 1000.0]. If the learning rate is too high, the data may look like a ‘ball’ with any point approximately equidistant from its nearest neighbours. If the learning rate is too low, most points may look compressed in a dense cloud with few outliers. If the cost function gets stuck in a bad local minimum increasing the learning rate may help.
Maximum number of iterations for the optimization. Should be at least 250.
Maximum number of iterations without progress before we abort the optimization, used after 250 initial iterations with early exaggeration. Note that progress is only checked every 50 iterations so this value is rounded to the next multiple of 50.
New in version 0.17: parameter n_iter_without_progress to control stopping criteria.
If the gradient norm is below this threshold, the optimization will be stopped.
The metric to use when calculating distance between instances in a feature array. If metric is a string, it must be one of the options allowed by scipy.spatial.distance.pdist for its metric parameter, or a metric listed in pairwise.PAIRWISE_DISTANCE_FUNCTIONS. If metric is “precomputed”, X is assumed to be a distance matrix. Alternatively, 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 from X as input and return a value indicating the distance between them. The default is “euclidean” which is interpreted as squared euclidean distance.
Initialization of embedding. Possible options are ‘random’, ‘pca’, and a numpy array of shape (n_samples, n_components). PCA initialization cannot be used with precomputed distances and is usually more globally stable than random initialization.
Verbosity level.
Determines the random number generator. Pass an int for reproducible results across multiple function calls. Note that different initializations might result in different local minima of the cost function. See :term: Glossary <random_state>.
By default the gradient calculation algorithm uses Barnes-Hut approximation running in O(NlogN) time. method=’exact’ will run on the slower, but exact, algorithm in O(N^2) time. The exact algorithm should be used when nearest-neighbor errors need to be better than 3%. However, the exact method cannot scale to millions of examples.
New in version 0.17: Approximate optimization method via the Barnes-Hut.
Only used if method=’barnes_hut’ This is the trade-off between speed and accuracy for Barnes-Hut T-SNE. ‘angle’ is the angular size (referred to as theta in [3]) of a distant node as measured from a point. If this size is below ‘angle’ then it is used as a summary node of all points contained within it. This method is not very sensitive to changes in this parameter in the range of 0.2 - 0.8. Angle less than 0.2 has quickly increasing computation time and angle greater 0.8 has quickly increasing error.
The number of parallel jobs to run for neighbors search. This parameter has no impact when metric="precomputed" or (metric="euclidean" and method="exact"). None means 1 unless in a joblib.parallel_backend context. -1 means using all processors. See Glossary for more details.
New in version 0.22.
Whether TSNE should square the distance values. 'legacy' means that distance values are squared only when metric="euclidean". True means that distance values are squared for all metrics.
New in version 0.24: Added to provide backward compatibility during deprecation of legacy squaring behavior.
Deprecated since version 0.24: Legacy squaring behavior was deprecated in 0.24. The 'legacy' value will be removed in 1.1 (renaming of 0.26), at which point the default value will change to True.
Stores the embedding vectors.
Kullback-Leibler divergence after optimization.
Number of iterations run.
Using t-SNE. Journal of Machine Learning Research 9:2579-2605, 2008.
https://lvdmaaten.github.io/tsne/
Journal of Machine Learning Research 15(Oct):3221-3245, 2014. https://lvdmaaten.github.io/publications/papers/JMLR_2014.pdf
fit(X[, y])
Fit X into an embedded space.
fit_transform(X[, y])
Fit X into an embedded space and return that transformed output.
get_params([deep])
Get parameters for this estimator.
set_params(**params)
Set the parameters of this estimator.
Fit X into an embedded space.
If the metric is ‘precomputed’ X must be a square distance matrix. Otherwise it contains a sample per row. If the method is ‘exact’, X may be a sparse matrix of type ‘csr’, ‘csc’ or ‘coo’. If the method is ‘barnes_hut’ and the metric is ‘precomputed’, X may be a precomputed sparse graph.
Fit X into an embedded space and return that transformed output.
If the metric is ‘precomputed’ X must be a square distance matrix. Otherwise it contains a sample per row. If the method is ‘exact’, X may be a sparse matrix of type ‘csr’, ‘csc’ or ‘coo’. If the method is ‘barnes_hut’ and the metric is ‘precomputed’, X may be a precomputed sparse graph.
Embedding of the training data in low-dimensional space.
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.


t-distributed Stochastic Neighbor Embedding.
t-SNE [1] is a tool to visualize high-dimensional data. It converts similarities between data points to joint probabilities and tries to minimize the Kullback-Leibler divergence between the joint probabilities of the low-dimensional embedding and the high-dimensional data. t-SNE has a cost function that is not convex, i.e. with different initializations we can get different results.
It is highly recommended to use another dimensionality reduction method (e.g. PCA for dense data or TruncatedSVD for sparse data) to reduce the number of dimensions to a reasonable amount (e.g. 50) if the number of features is very high. This will suppress some noise and speed up the computation of pairwise distances between samples. For more tips see Laurens van der Maaten’s FAQ [2].
Read more in the User Guide.
Dimension of the embedded space.
The perplexity is related to the number of nearest neighbors that is used in other manifold learning algorithms. Larger datasets usually require a larger perplexity. Consider selecting a value between 5 and 50. Different values can result in significantly different results.
Controls how tight natural clusters in the original space are in the embedded space and how much space will be between them. For larger values, the space between natural clusters will be larger in the embedded space. Again, the choice of this parameter is not very critical. If the cost function increases during initial optimization, the early exaggeration factor or the learning rate might be too high.
The learning rate for t-SNE is usually in the range [10.0, 1000.0]. If the learning rate is too high, the data may look like a ‘ball’ with any point approximately equidistant from its nearest neighbours. If the learning rate is too low, most points may look compressed in a dense cloud with few outliers. If the cost function gets stuck in a bad local minimum increasing the learning rate may help.
Maximum number of iterations for the optimization. Should be at least 250.
Maximum number of iterations without progress before we abort the optimization, used after 250 initial iterations with early exaggeration. Note that progress is only checked every 50 iterations so this value is rounded to the next multiple of 50.
New in version 0.17: parameter n_iter_without_progress to control stopping criteria.
If the gradient norm is below this threshold, the optimization will be stopped.
The metric to use when calculating distance between instances in a feature array. If metric is a string, it must be one of the options allowed by scipy.spatial.distance.pdist for its metric parameter, or a metric listed in pairwise.PAIRWISE_DISTANCE_FUNCTIONS. If metric is “precomputed”, X is assumed to be a distance matrix. Alternatively, 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 from X as input and return a value indicating the distance between them. The default is “euclidean” which is interpreted as squared euclidean distance.
Initialization of embedding. Possible options are ‘random’, ‘pca’, and a numpy array of shape (n_samples, n_components). PCA initialization cannot be used with precomputed distances and is usually more globally stable than random initialization.
Verbosity level.
Determines the random number generator. Pass an int for reproducible results across multiple function calls. Note that different initializations might result in different local minima of the cost function. See :term: Glossary <random_state>.
By default the gradient calculation algorithm uses Barnes-Hut approximation running in O(NlogN) time. method=’exact’ will run on the slower, but exact, algorithm in O(N^2) time. The exact algorithm should be used when nearest-neighbor errors need to be better than 3%. However, the exact method cannot scale to millions of examples.
New in version 0.17: Approximate optimization method via the Barnes-Hut.
Only used if method=’barnes_hut’ This is the trade-off between speed and accuracy for Barnes-Hut T-SNE. ‘angle’ is the angular size (referred to as theta in [3]) of a distant node as measured from a point. If this size is below ‘angle’ then it is used as a summary node of all points contained within it. This method is not very sensitive to changes in this parameter in the range of 0.2 - 0.8. Angle less than 0.2 has quickly increasing computation time and angle greater 0.8 has quickly increasing error.
The number of parallel jobs to run for neighbors search. This parameter has no impact when metric="precomputed" or (metric="euclidean" and method="exact"). None means 1 unless in a joblib.parallel_backend context. -1 means using all processors. See Glossary for more details.
New in version 0.22.
Whether TSNE should square the distance values. 'legacy' means that distance values are squared only when metric="euclidean". True means that distance values are squared for all metrics.
New in version 0.24: Added to provide backward compatibility during deprecation of legacy squaring behavior.
Deprecated since version 0.24: Legacy squaring behavior was deprecated in 0.24. The 'legacy' value will be removed in 1.1 (renaming of 0.26), at which point the default value will change to True.
Stores the embedding vectors.
Kullback-Leibler divergence after optimization.
Number of iterations run.
Using t-SNE. Journal of Machine Learning Research 9:2579-2605, 2008.
https://lvdmaaten.github.io/tsne/
Journal of Machine Learning Research 15(Oct):3221-3245, 2014. https://lvdmaaten.github.io/publications/papers/JMLR_2014.pdf
fit(X[, y])
Fit X into an embedded space.
fit_transform(X[, y])
Fit X into an embedded space and return that transformed output.
get_params([deep])
Get parameters for this estimator.
set_params(**params)
Set the parameters of this estimator.
Fit X into an embedded space.
If the metric is ‘precomputed’ X must be a square distance matrix. Otherwise it contains a sample per row. If the method is ‘exact’, X may be a sparse matrix of type ‘csr’, ‘csc’ or ‘coo’. If the method is ‘barnes_hut’ and the metric is ‘precomputed’, X may be a precomputed sparse graph.
Fit X into an embedded space and return that transformed output.
If the metric is ‘precomputed’ X must be a square distance matrix. Otherwise it contains a sample per row. If the method is ‘exact’, X may be a sparse matrix of type ‘csr’, ‘csc’ or ‘coo’. If the method is ‘barnes_hut’ and the metric is ‘precomputed’, X may be a precomputed sparse graph.
Embedding of the training data in low-dimensional space.
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.
Comparison of Manifold Learning methods
t-SNE: The effect of various perplexity values on the shape
Manifold Learning methods on a severed sphere
Manifold learning on handwritten digits: Locally Linear Embedding, Isomap…
Approximate nearest neighbors in TSNE


Fit X into an embedded space.
If the metric is ‘precomputed’ X must be a square distance matrix. Otherwise it contains a sample per row. If the method is ‘exact’, X may be a sparse matrix of type ‘csr’, ‘csc’ or ‘coo’. If the method is ‘barnes_hut’ and the metric is ‘precomputed’, X may be a precomputed sparse graph.


Fit X into an embedded space and return that transformed output.
If the metric is ‘precomputed’ X must be a square distance matrix. Otherwise it contains a sample per row. If the method is ‘exact’, X may be a sparse matrix of type ‘csr’, ‘csc’ or ‘coo’. If the method is ‘barnes_hut’ and the metric is ‘precomputed’, X may be a precomputed sparse graph.
Embedding of the training data in low-dimensional space.


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.


Accuracy classification score.
In multilabel classification, this function computes subset accuracy: the set of labels predicted for a sample must exactly match the corresponding set of labels in y_true.
Read more in the User Guide.
Ground truth (correct) labels.
Predicted labels, as returned by a classifier.
If False, return the number of correctly classified samples. Otherwise, return the fraction of correctly classified samples.
Sample weights.
If normalize == True, return the fraction of correctly classified samples (float), else returns the number of correctly classified samples (int).
The best performance is 1 with normalize == True and the number of samples with normalize == False.
See also
In binary and multiclass classification, this function is equal to the jaccard_score function.
In the multilabel case with binary label indicators:


Adjusted Mutual Information between two clusterings.
Adjusted Mutual Information (AMI) is an adjustment of the Mutual Information (MI) score to account for chance. It accounts for the fact that the MI is generally higher for two clusterings with a larger number of clusters, regardless of whether there is actually more information shared. For two clusterings \(U\) and \(V\), the AMI is given as:
This metric is independent of the absolute values of the labels: a permutation of the class or cluster label values won’t change the score value in any way.
This metric is furthermore symmetric: switching label_true with label_pred will return the same score value. This can be useful to measure the agreement of two independent label assignments strategies on the same dataset when the real ground truth is not known.
Be mindful that this function is an order of magnitude slower than other metrics, such as the Adjusted Rand Index.
Read more in the User Guide.
A clustering of the data into disjoint subsets.
A clustering of the data into disjoint subsets.
How to compute the normalizer in the denominator. Possible options are ‘min’, ‘geometric’, ‘arithmetic’, and ‘max’.
New in version 0.20.
Changed in version 0.22: The default value of average_method changed from ‘max’ to ‘arithmetic’.
The AMI returns a value of 1 when the two partitions are identical (ie perfectly matched). Random partitions (independent labellings) have an expected AMI around 0 on average hence can be negative.
See also
Adjusted Rand Index.
Mutual Information (not adjusted for chance).
Vinh, Epps, and Bailey, (2010). Information Theoretic Measures for Clusterings Comparison: Variants, Properties, Normalization and Correction for Chance, JMLR
Wikipedia entry for the Adjusted Mutual Information
Perfect labelings are both homogeneous and complete, hence have score 1.0:
If classes members are completely split across different clusters, the assignment is totally in-complete, hence the AMI is null:


Rand index adjusted for chance.
The Rand Index computes a similarity measure between two clusterings by considering all pairs of samples and counting pairs that are assigned in the same or different clusters in the predicted and true clusterings.
The raw RI score is then “adjusted for chance” into the ARI score using the following scheme:
The adjusted Rand index is thus ensured to have a value close to 0.0 for random labeling independently of the number of clusters and samples and exactly 1.0 when the clusterings are identical (up to a permutation).
ARI is a symmetric measure:
Read more in the User Guide.
Ground truth class labels to be used as a reference
Cluster labels to evaluate
Similarity score between -1.0 and 1.0. Random labelings have an ARI close to 0.0. 1.0 stands for perfect match.
See also
Adjusted Mutual Information.
L. Hubert and P. Arabie, Comparing Partitions, Journal of Classification 1985 https://link.springer.com/article/10.1007%2FBF01908075
D. Steinley, Properties of the Hubert-Arabie adjusted Rand index, Psychological Methods 2004
https://en.wikipedia.org/wiki/Rand_index#Adjusted_Rand_index
Perfectly matching labelings have a score of 1 even
Labelings that assign all classes members to the same clusters are complete but may not always be pure, hence penalized:
ARI is symmetric, so labelings that have pure clusters with members coming from the same classes but unnecessary splits are penalized:
If classes members are completely split across different clusters, the assignment is totally incomplete, hence the ARI is very low:


Compute Area Under the Curve (AUC) using the trapezoidal rule.
This is a general function, given points on a curve. For computing the area under the ROC-curve, see roc_auc_score. For an alternative way to summarize a precision-recall curve, see average_precision_score.
x coordinates. These must be either monotonic increasing or monotonic decreasing.
y coordinates.
See also
Compute the area under the ROC curve.
Compute average precision from prediction scores.
Compute precision-recall pairs for different probability thresholds.


Compute average precision (AP) from prediction scores.
AP summarizes a precision-recall curve as the weighted mean of precisions achieved at each threshold, with the increase in recall from the previous threshold used as the weight:
where \(P_n\) and \(R_n\) are the precision and recall at the nth threshold [1]. This implementation is not interpolated and is different from computing the area under the precision-recall curve with the trapezoidal rule, which uses linear interpolation and can be too optimistic.
Note: this implementation is restricted to the binary classification task or multilabel classification task.
Read more in the User Guide.
True binary labels or binary label indicators.
Target scores, can either be probability estimates of the positive class, confidence values, or non-thresholded measure of decisions (as returned by decision_function on some classifiers).
If None, the scores for each class are returned. Otherwise, this determines the type of averaging performed on the data:
Calculate metrics globally by considering each element of the label indicator matrix as a label.
Calculate metrics for each label, and find their unweighted mean. This does not take label imbalance into account.
Calculate metrics for each label, and find their average, weighted by support (the number of true instances for each label).
Calculate metrics for each instance, and find their average.
Will be ignored when y_true is binary.
The label of the positive class. Only applied to binary y_true. For multilabel-indicator y_true, pos_label is fixed to 1.
Sample weights.
See also
Compute the area under the ROC curve.
Compute precision-recall pairs for different probability thresholds.
Changed in version 0.19: Instead of linearly interpolating between operating points, precisions are weighted by the change in recall since the last operating point.
Wikipedia entry for the Average precision


Compute the balanced accuracy.
The balanced accuracy in binary and multiclass classification problems to deal with imbalanced datasets. It is defined as the average of recall obtained on each class.
The best value is 1 and the worst value is 0 when adjusted=False.
Read more in the User Guide.
New in version 0.20.
Ground truth (correct) target values.
Estimated targets as returned by a classifier.
Sample weights.
When true, the result is adjusted for chance, so that random performance would score 0, and perfect performance scores 1.
See also
Some literature promotes alternative definitions of balanced accuracy. Our definition is equivalent to accuracy_score with class-balanced sample weights, and shares desirable properties with the binary case. See the User Guide.
Brodersen, K.H.; Ong, C.S.; Stephan, K.E.; Buhmann, J.M. (2010). The balanced accuracy and its posterior distribution. Proceedings of the 20th International Conference on Pattern Recognition, 3121-24.
John. D. Kelleher, Brian Mac Namee, Aoife D’Arcy, (2015). Fundamentals of Machine Learning for Predictive Data Analytics: Algorithms, Worked Examples, and Case Studies.


Compute the Brier score loss.
The smaller the Brier score loss, the better, hence the naming with “loss”. The Brier score measures the mean squared difference between the predicted probability and the actual outcome. The Brier score always takes on a value between zero and one, since this is the largest possible difference between a predicted probability (which must be between zero and one) and the actual outcome (which can take on values of only 0 and 1). It can be decomposed is the sum of refinement loss and calibration loss.
The Brier score is appropriate for binary and categorical outcomes that can be structured as true or false, but is inappropriate for ordinal variables which can take on three or more values (this is because the Brier score assumes that all possible outcomes are equivalently “distant” from one another). Which label is considered to be the positive label is controlled via the parameter pos_label, which defaults to the greater label unless y_true is all 0 or all -1, in which case pos_label defaults to 1.
Read more in the User Guide.
True targets.
Probabilities of the positive class.
Sample weights.
Label of the positive class. pos_label will be infered in the following manner:
Brier score loss.
Wikipedia entry for the Brier score.


Compute the Calinski and Harabasz score.
It is also known as the Variance Ratio Criterion.
The score is defined as ratio between the within-cluster dispersion and the between-cluster dispersion.
Read more in the User Guide.
A list of n_features-dimensional data points. Each row corresponds to a single data point.
Predicted labels for each sample.
The resulting Calinski-Harabasz score.
T. Calinski and J. Harabasz, 1974. “A dendrite method for cluster analysis”. Communications in Statistics


Determine scorer from user options.
A TypeError will be thrown if the estimator cannot be scored.
The object to use to fit the data.
A string (see model evaluation documentation) or a scorer callable object / function with signature scorer(estimator, X, y).
If no scoring is specified and the estimator has no score function, we can either return None or raise an exception.
A scorer callable object / function with signature scorer(estimator, X, y).


Build a text report showing the main classification metrics.
Read more in the User Guide.
Ground truth (correct) target values.
Estimated targets as returned by a classifier.
Optional list of label indices to include in the report.
Optional display names matching the labels (same order).
Sample weights.
Number of digits for formatting output floating point values. When output_dict is True, this will be ignored and the returned values will not be rounded.
If True, return output as dict.
New in version 0.20.
Sets the value to return when there is a zero division. If set to “warn”, this acts as 0, but warnings are also raised.
Text summary of the precision, recall, F1 score for each class. Dictionary returned if output_dict is True. Dictionary has the following structure:
The reported averages include macro average (averaging the unweighted mean per label), weighted average (averaging the support-weighted mean per label), and sample average (only for multilabel classification). Micro average (averaging the total true positives, false negatives and false positives) is only shown for multi-label or multi-class with a subset of classes, because it corresponds to accuracy otherwise and would be the same for all metrics. See also precision_recall_fscore_support for more details on averages.
Note that in binary classification, recall of the positive class is also known as “sensitivity”; recall of the negative class is “specificity”.
See also


Build a contingency matrix describing the relationship between labels.
Ground truth class labels to be used as a reference.
Cluster labels to evaluate.
If a float, that value is added to all values in the contingency matrix. This helps to stop NaN propagation. If None, nothing is adjusted.
If True, return a sparse CSR continency matrix. If eps is not None and sparse is True will raise ValueError.
New in version 0.18.
Output dtype. Ignored if eps is not None.
New in version 0.24.
Matrix \(C\) such that \(C_{i, j}\) is the number of samples in true class \(i\) and in predicted class \(j\). If eps is None, the dtype of this array will be integer unless set otherwise with the dtype argument. If eps is given, the dtype will be float. Will be a sklearn.sparse.csr_matrix if sparse=True.


Pair confusion matrix arising from two clusterings.
The pair confusion matrix \(C\) computes a 2 by 2 similarity matrix between two clusterings by considering all pairs of samples and counting pairs that are assigned into the same or into different clusters under the true and predicted clusterings.
Considering a pair of samples that is clustered together a positive pair, then as in binary classification the count of true negatives is \(C_{00}\), false negatives is \(C_{10}\), true positives is \(C_{11}\) and false positives is \(C_{01}\).
Read more in the User Guide.
Ground truth class labels to be used as a reference.
Cluster labels to evaluate.
The contingency matrix.
See also
Rand Score
Adjusted Rand Score
Adjusted Mutual Information
Perfectly matching labelings have all non-zero entries on the diagonal regardless of actual label values:
Labelings that assign all classes members to the same clusters are complete but may be not always pure, hence penalized, and have some off-diagonal non-zero entries:
Note that the matrix is not symmetric.


Cohen’s kappa: a statistic that measures inter-annotator agreement.
This function computes Cohen’s kappa [1], a score that expresses the level of agreement between two annotators on a classification problem. It is defined as
where \(p_o\) is the empirical probability of agreement on the label assigned to any sample (the observed agreement ratio), and \(p_e\) is the expected agreement when both annotators assign labels randomly. \(p_e\) is estimated using a per-annotator empirical prior over the class labels [2].
Read more in the User Guide.
Labels assigned by the first annotator.
Labels assigned by the second annotator. The kappa statistic is symmetric, so swapping y1 and y2 doesn’t change the value.
List of labels to index the matrix. This may be used to select a subset of labels. If None, all labels that appear at least once in y1 or y2 are used.
Weighting type to calculate the score. None means no weighted; “linear” means linear weighted; “quadratic” means quadratic weighted.
Sample weights.
The kappa statistic, which is a number between -1 and 1. The maximum value means complete agreement; zero or lower means chance agreement.
J. Cohen (1960). “A coefficient of agreement for nominal scales”. Educational and Psychological Measurement 20(1):37-46. doi:10.1177/001316446002000104.
R. Artstein and M. Poesio (2008). “Inter-coder agreement for computational linguistics”. Computational Linguistics 34(4):555-596.
Wikipedia entry for the Cohen’s kappa.


Completeness metric of a cluster labeling given a ground truth.
A clustering result satisfies completeness if all the data points that are members of a given class are elements of the same cluster.
This metric is independent of the absolute values of the labels: a permutation of the class or cluster label values won’t change the score value in any way.
This metric is not symmetric: switching label_true with label_pred will return the homogeneity_score which will be different in general.
Read more in the User Guide.
ground truth class labels to be used as a reference
cluster labels to evaluate
score between 0.0 and 1.0. 1.0 stands for perfectly complete labeling
See also
Andrew Rosenberg and Julia Hirschberg, 2007. V-Measure: A conditional entropy-based external cluster evaluation measure
Perfect labelings are complete:
Non-perfect labelings that assign all classes members to the same clusters are still complete:
If classes members are split across different clusters, the assignment cannot be complete:


Confusion Matrix visualization.
It is recommend to use plot_confusion_matrix to create a ConfusionMatrixDisplay. All parameters are stored as attributes.
Read more in the User Guide.
Confusion matrix.
Display labels for plot. If None, display labels are set from 0 to n_classes - 1.
Image representing the confusion matrix.
Array of matplotlib axes. None if include_values is false.
Axes with confusion matrix.
Figure containing the confusion matrix.
See also
Compute Confusion Matrix to evaluate the accuracy of a classification.
Plot Confusion Matrix.
plot(*[, include_values, cmap, …])
Plot visualization.
Plot visualization.
Includes values in confusion matrix.
Colormap recognized by matplotlib.
Rotation of xtick labels.
Format specification for values in confusion matrix. If None, the format specification is ‘d’ or ‘.2g’ whichever is shorter.
Axes object to plot on. If None, a new figure and axes is created.
Whether or not to add a colorbar to the plot.


Confusion Matrix visualization.
It is recommend to use plot_confusion_matrix to create a ConfusionMatrixDisplay. All parameters are stored as attributes.
Read more in the User Guide.
Confusion matrix.
Display labels for plot. If None, display labels are set from 0 to n_classes - 1.
Image representing the confusion matrix.
Array of matplotlib axes. None if include_values is false.
Axes with confusion matrix.
Figure containing the confusion matrix.
See also
Compute Confusion Matrix to evaluate the accuracy of a classification.
Plot Confusion Matrix.
plot(*[, include_values, cmap, …])
Plot visualization.
Plot visualization.
Includes values in confusion matrix.
Colormap recognized by matplotlib.
Rotation of xtick labels.
Format specification for values in confusion matrix. If None, the format specification is ‘d’ or ‘.2g’ whichever is shorter.
Axes object to plot on. If None, a new figure and axes is created.
Whether or not to add a colorbar to the plot.
Visualizations with Display Objects


Plot visualization.
Includes values in confusion matrix.
Colormap recognized by matplotlib.
Rotation of xtick labels.
Format specification for values in confusion matrix. If None, the format specification is ‘d’ or ‘.2g’ whichever is shorter.
Axes object to plot on. If None, a new figure and axes is created.
Whether or not to add a colorbar to the plot.


Compute confusion matrix to evaluate the accuracy of a classification.
By definition a confusion matrix \(C\) is such that \(C_{i, j}\) is equal to the number of observations known to be in group \(i\) and predicted to be in group \(j\).
Thus in binary classification, the count of true negatives is \(C_{0,0}\), false negatives is \(C_{1,0}\), true positives is \(C_{1,1}\) and false positives is \(C_{0,1}\).
Read more in the User Guide.
Ground truth (correct) target values.
Estimated targets as returned by a classifier.
List of labels to index the matrix. This may be used to reorder or select a subset of labels. If None is given, those that appear at least once in y_true or y_pred are used in sorted order.
Sample weights.
New in version 0.18.
Normalizes confusion matrix over the true (rows), predicted (columns) conditions or all the population. If None, confusion matrix will not be normalized.
Confusion matrix whose i-th row and j-th column entry indicates the number of samples with true label being i-th class and predicted label being j-th class.
See also
Plot Confusion Matrix.
Confusion Matrix visualization.
Wikipedia entry for the Confusion matrix (Wikipedia and other references may use a different convention for axes).
In the binary case, we can extract true positives, etc as follows:


The similarity of two sets of biclusters.
Similarity between individual biclusters is computed. Then the best matching between sets is found using the Hungarian algorithm. The final score is the sum of similarities divided by the size of the larger set.
Read more in the User Guide.
Tuple of row and column indicators for a set of biclusters.
Another set of biclusters like a.
May be the string “jaccard” to use the Jaccard coefficient, or any function that takes four arguments, each of which is a 1d indicator vector: (a_rows, a_columns, b_rows, b_columns).


Coverage error measure.
Compute how far we need to go through the ranked scores to cover all true labels. The best value is equal to the average number of labels in y_true per sample.
Ties in y_scores are broken by giving maximal rank that would have been assigned to all tied values.
Note: Our implementation’s score is 1 greater than the one given in Tsoumakas et al., 2010. This extends it to handle the degenerate case in which an instance has 0 true labels.
Read more in the User Guide.
True binary labels in binary indicator format.
Target scores, can either be probability estimates of the positive class, confidence values, or non-thresholded measure of decisions (as returned by “decision_function” on some classifiers).
Sample weights.
Tsoumakas, G., Katakis, I., & Vlahavas, I. (2010). Mining multi-label data. In Data mining and knowledge discovery handbook (pp. 667-685). Springer US.


Computes the Davies-Bouldin score.
The score is defined as the average similarity measure of each cluster with its most similar cluster, where similarity is the ratio of within-cluster distances to between-cluster distances. Thus, clusters which are farther apart and less dispersed will result in a better score.
The minimum score is zero, with lower values indicating better clustering.
Read more in the User Guide.
New in version 0.20.
A list of n_features-dimensional data points. Each row corresponds to a single data point.
Predicted labels for each sample.
The resulting Davies-Bouldin score.
Davies, David L.; Bouldin, Donald W. (1979). “A Cluster Separation Measure”. IEEE Transactions on Pattern Analysis and Machine Intelligence. PAMI-1 (2): 224-227


Compute Discounted Cumulative Gain.
Sum the true scores ranked in the order induced by the predicted scores, after applying a logarithmic discount.
This ranking metric yields a high value if true labels are ranked high by y_score.
Usually the Normalized Discounted Cumulative Gain (NDCG, computed by ndcg_score) is preferred.
True targets of multilabel classification, or true scores of entities to be ranked.
Target scores, can either be probability estimates, confidence values, or non-thresholded measure of decisions (as returned by “decision_function” on some classifiers).
Only consider the highest k scores in the ranking. If None, use all outputs.
Base of the logarithm used for the discount. A low value means a sharper discount (top results are more important).
Sample weights. If None, all samples are given the same weight.
Assume that there are no ties in y_score (which is likely to be the case if y_score is continuous) for efficiency gains.
The averaged sample DCG scores.
See also
The Discounted Cumulative Gain divided by the Ideal Discounted Cumulative Gain (the DCG obtained for a perfect ranking), in order to have a score between 0 and 1.
Wikipedia entry for Discounted Cumulative Gain.
Jarvelin, K., & Kekalainen, J. (2002). Cumulated gain-based evaluation of IR techniques. ACM Transactions on Information Systems (TOIS), 20(4), 422-446.
Wang, Y., Wang, L., Li, Y., He, D., Chen, W., & Liu, T. Y. (2013, May). A theoretical analysis of NDCG ranking measures. In Proceedings of the 26th Annual Conference on Learning Theory (COLT 2013).
McSherry, F., & Najork, M. (2008, March). Computing information retrieval performance measures efficiently in the presence of tied scores. In European conference on information retrieval (pp. 414-421). Springer, Berlin, Heidelberg.


DET curve visualization.
It is recommend to use plot_det_curve to create a visualizer. All parameters are stored as attributes.
Read more in the User Guide.
New in version 0.24.
False positive rate.
True positive rate.
Name of estimator. If None, the estimator name is not shown.
The label of the positive class.
DET Curve.
Axes with DET Curve.
Figure containing the curve.
See also
Compute error rates for different probability thresholds.
Plot detection error tradeoff (DET) curve.
plot([ax, name])
Plot visualization.
Plot visualization.
Axes object to plot on. If None, a new figure and axes is created.
Name of DET curve for labeling. If None, use the name of the estimator.
Object that stores computed values.


Plot visualization.
Axes object to plot on. If None, a new figure and axes is created.
Name of DET curve for labeling. If None, use the name of the estimator.
Object that stores computed values.


Compute error rates for different probability thresholds.
Note
This metric is used for evaluation of ranking and error tradeoffs of a binary classification task.
Read more in the User Guide.
New in version 0.24.
True binary labels. If labels are not either {-1, 1} or {0, 1}, then pos_label should be explicitly given.
Target scores, can either be probability estimates of the positive class, confidence values, or non-thresholded measure of decisions (as returned by “decision_function” on some classifiers).
The label of the positive class. When pos_label=None, if y_true is in {-1, 1} or {0, 1}, pos_label is set to 1, otherwise an error will be raised.
Sample weights.
False positive rate (FPR) such that element i is the false positive rate of predictions with score >= thresholds[i]. This is occasionally referred to as false acceptance propability or fall-out.
False negative rate (FNR) such that element i is the false negative rate of predictions with score >= thresholds[i]. This is occasionally referred to as false rejection or miss rate.
Decreasing score values.
See also
Plot detection error tradeoff (DET) curve.
DET curve visualization.
Compute Receiver operating characteristic (ROC) curve.
Compute precision-recall curve.


Explained variance regression score function.
Best possible score is 1.0, lower values are worse.
Read more in the User Guide.
Ground truth (correct) target values.
Estimated target values.
Sample weights.
Defines aggregating of multiple output scores. Array-like value defines weights used to average scores.
Returns a full set of scores in case of multioutput input.
Scores of all outputs are averaged with uniform weight.
Scores of all outputs are averaged, weighted by the variances of each individual output.
The explained variance or ndarray if ‘multioutput’ is ‘raw_values’.
This is not a symmetric function.


Compute the F1 score, also known as balanced F-score or F-measure.
The F1 score can be interpreted as a weighted average of the precision and recall, where an F1 score reaches its best value at 1 and worst score at 0. The relative contribution of precision and recall to the F1 score are equal. The formula for the F1 score is:
In the multi-class and multi-label case, this is the average of the F1 score of each class with weighting depending on the average parameter.
Read more in the User Guide.
Ground truth (correct) target values.
Estimated targets as returned by a classifier.
The set of labels to include when average != 'binary', and their order if average is None. Labels present in the data can be excluded, for example to calculate a multiclass average ignoring a majority negative class, while labels not present in the data will result in 0 components in a macro average. For multilabel targets, labels are column indices. By default, all labels in y_true and y_pred are used in sorted order.
Changed in version 0.17: Parameter labels improved for multiclass problem.
The class to report if average='binary' and the data is binary. If the data are multiclass or multilabel, this will be ignored; setting labels=[pos_label] and average != 'binary' will report scores for that label only.
This parameter is required for multiclass/multilabel targets. If None, the scores for each class are returned. Otherwise, this determines the type of averaging performed on the data:
Only report results for the class specified by pos_label. This is applicable only if targets (y_{true,pred}) are binary.
Calculate metrics globally by counting the total true positives, false negatives and false positives.
Calculate metrics for each label, and find their unweighted mean. This does not take label imbalance into account.
Calculate metrics for each label, and find their average weighted by support (the number of true instances for each label). This alters ‘macro’ to account for label imbalance; it can result in an F-score that is not between precision and recall.
Calculate metrics for each instance, and find their average (only meaningful for multilabel classification where this differs from accuracy_score).
Sample weights.
Sets the value to return when there is a zero division, i.e. when all predictions and labels are negative. If set to “warn”, this acts as 0, but warnings are also raised.
F1 score of the positive class in binary classification or weighted average of the F1 scores of each class for the multiclass task.
See also
When true positive + false positive == 0, precision is undefined. When true positive + false negative == 0, recall is undefined. In such cases, by default the metric will be set to 0, as will f-score, and UndefinedMetricWarning will be raised. This behavior can be modified with zero_division.
Wikipedia entry for the F1-score.


Compute the F-beta score.
The F-beta score is the weighted harmonic mean of precision and recall, reaching its optimal value at 1 and its worst value at 0.
The beta parameter determines the weight of recall in the combined score. beta < 1 lends more weight to precision, while beta > 1 favors recall (beta -> 0 considers only precision, beta -> +inf only recall).
Read more in the User Guide.
Ground truth (correct) target values.
Estimated targets as returned by a classifier.
Determines the weight of recall in the combined score.
The set of labels to include when average != 'binary', and their order if average is None. Labels present in the data can be excluded, for example to calculate a multiclass average ignoring a majority negative class, while labels not present in the data will result in 0 components in a macro average. For multilabel targets, labels are column indices. By default, all labels in y_true and y_pred are used in sorted order.
Changed in version 0.17: Parameter labels improved for multiclass problem.
The class to report if average='binary' and the data is binary. If the data are multiclass or multilabel, this will be ignored; setting labels=[pos_label] and average != 'binary' will report scores for that label only.
This parameter is required for multiclass/multilabel targets. If None, the scores for each class are returned. Otherwise, this determines the type of averaging performed on the data:
Only report results for the class specified by pos_label. This is applicable only if targets (y_{true,pred}) are binary.
Calculate metrics globally by counting the total true positives, false negatives and false positives.
Calculate metrics for each label, and find their unweighted mean. This does not take label imbalance into account.
Calculate metrics for each label, and find their average weighted by support (the number of true instances for each label). This alters ‘macro’ to account for label imbalance; it can result in an F-score that is not between precision and recall.
Calculate metrics for each instance, and find their average (only meaningful for multilabel classification where this differs from accuracy_score).
Sample weights.
Sets the value to return when there is a zero division, i.e. when all predictions and labels are negative. If set to “warn”, this acts as 0, but warnings are also raised.
F-beta score of the positive class in binary classification or weighted average of the F-beta score of each class for the multiclass task.
See also
When true positive + false positive == 0 or true positive + false negative == 0, f-score returns 0 and raises UndefinedMetricWarning. This behavior can be modified with zero_division.
R. Baeza-Yates and B. Ribeiro-Neto (2011). Modern Information Retrieval. Addison Wesley, pp. 327-328.
Wikipedia entry for the F1-score.