Computes the log-likelihood of a Gaussian data set with self.covariance_ as an estimator of its covariance matrix.
Test data of which we compute the likelihood, where n_samples is the number of samples and n_features is the number of features. X_test is assumed to be drawn from the same distribution than the data used in fit (including centering).
Not used, present for API consistency by convention.
The likelihood of the data set with self.covariance_ as an estimator of its covariance matrix.


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


Computes the Maximum likelihood covariance estimator
Data from which to compute the covariance estimate
If True, data will not be centered before computation. Useful when working with data whose mean is almost, but not exactly zero. If False, data will be centered before computation.
Empirical covariance (Maximum Likelihood Estimator).


Sparse inverse covariance estimation with an l1-penalized estimator.
Read more in the User Guide.
Changed in version v0.20: GraphLasso has been renamed to GraphicalLasso
The regularization parameter: the higher alpha, the more regularization, the sparser the inverse covariance. Range is (0, inf].
The Lasso solver to use: coordinate descent or LARS. Use LARS for very sparse underlying graphs, where p > n. Elsewhere prefer cd which is more numerically stable.
The tolerance to declare convergence: if the dual gap goes below this value, iterations are stopped. Range is (0, inf].
The tolerance for the elastic net solver used to calculate the descent direction. This parameter controls the accuracy of the search direction for a given column update, not of the overall parameter estimate. Only used for mode=’cd’. Range is (0, inf].
The maximum number of iterations.
If verbose is True, the objective function and dual gap are plotted at each iteration.
If True, data are not centered before computation. Useful when working with data whose mean is almost, but not exactly zero. If False, data are centered before computation.
Estimated location, i.e. the estimated mean.
Estimated covariance matrix
Estimated pseudo inverse matrix.
Number of iterations run.
See also
error_norm(comp_cov[, norm, scaling, squared])
Computes the Mean Squared Error between two covariance estimators.
fit(X[, y])
Fits the GraphicalLasso model to X.
get_params([deep])
Get parameters for this estimator.
get_precision()
Getter for the precision matrix.
mahalanobis(X)
Computes the squared Mahalanobis distances of given observations.
score(X_test[, y])
Computes the log-likelihood of a Gaussian data set with self.covariance_ as an estimator of its covariance matrix.
set_params(**params)
Set the parameters of this estimator.
Computes the Mean Squared Error between two covariance estimators. (In the sense of the Frobenius norm).
The covariance to compare with.
The type of norm used to compute the error. Available error types: - ‘frobenius’ (default): sqrt(tr(A^t.A)) - ‘spectral’: sqrt(max(eigenvalues(A^t.A)) where A is the error (comp_cov - self.covariance_).
If True (default), the squared error norm is divided by n_features. If False, the squared error norm is not rescaled.
Whether to compute the squared error norm or the error norm. If True (default), the squared error norm is returned. If False, the error norm is returned.
The Mean Squared Error (in the sense of the Frobenius norm) between self and comp_cov covariance estimators.
Fits the GraphicalLasso model to X.
Data from which to compute the covariance estimate
Not used, present for API consistency by convention.
Get parameters for this estimator.
If True, will return the parameters for this estimator and contained subobjects that are estimators.
Parameter names mapped to their values.
Getter for the precision matrix.
The precision matrix associated to the current covariance object.
Computes the squared Mahalanobis distances of given observations.
The observations, the Mahalanobis distances of the which we compute. Observations are assumed to be drawn from the same distribution than the data used in fit.
Squared Mahalanobis distances of the observations.
Computes the log-likelihood of a Gaussian data set with self.covariance_ as an estimator of its covariance matrix.
Test data of which we compute the likelihood, where n_samples is the number of samples and n_features is the number of features. X_test is assumed to be drawn from the same distribution than the data used in fit (including centering).
Not used, present for API consistency by convention.
The likelihood of the data set with self.covariance_ as an estimator of its covariance matrix.
Set the parameters of this estimator.
The method works on simple estimators as well as on nested objects (such as Pipeline). The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.
Estimator parameters.
Estimator instance.


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


Fits the GraphicalLasso model to X.
Data from which to compute the covariance estimate
Not used, present for API consistency by convention.


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


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


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


Sparse inverse covariance w/ cross-validated choice of the l1 penalty.
See glossary entry for cross-validation estimator.
Read more in the User Guide.
Changed in version v0.20: GraphLassoCV has been renamed to GraphicalLassoCV
If an integer is given, it fixes the number of points on the grids of alpha to be used. If a list is given, it gives the grid to be used. See the notes in the class docstring for more details. Range is (0, inf] when floats given.
The number of times the grid is refined. Not used if explicit values of alphas are passed. Range is [1, inf).
Determines the cross-validation splitting strategy. Possible inputs for cv are:
For integer/None inputs KFold is used.
Refer User Guide for the various cross-validation strategies that can be used here.
Changed in version 0.20: cv default value if None changed from 3-fold to 5-fold.
The tolerance to declare convergence: if the dual gap goes below this value, iterations are stopped. Range is (0, inf].
The tolerance for the elastic net solver used to calculate the descent direction. This parameter controls the accuracy of the search direction for a given column update, not of the overall parameter estimate. Only used for mode=’cd’. Range is (0, inf].
Maximum number of iterations.
The Lasso solver to use: coordinate descent or LARS. Use LARS for very sparse underlying graphs, where number of features is greater than number of samples. Elsewhere prefer cd which is more numerically stable.
number of jobs to run in parallel. None means 1 unless in a joblib.parallel_backend context. -1 means using all processors. See Glossary for more details.
Changed in version v0.20: n_jobs default changed from 1 to None
If verbose is True, the objective function and duality gap are printed at each iteration.
If True, data are not centered before computation. Useful when working with data whose mean is almost, but not exactly zero. If False, data are centered before computation.
Estimated location, i.e. the estimated mean.
Estimated covariance matrix.
Estimated precision matrix (inverse covariance).
Penalization parameter selected.
All penalization parameters explored.
Deprecated since version 0.24: The cv_alphas_ attribute is deprecated in version 0.24 in favor of cv_results_['alphas'] and will be removed in version 1.1 (renaming of 0.26).
Log-likelihood score on left-out data across folds.
Deprecated since version 0.24: The grid_scores_ attribute is deprecated in version 0.24 in favor of cv_results_ and will be removed in version 1.1 (renaming of 0.26).
A dict with keys:
All penalization parameters explored.
Log-likelihood score on left-out data across (k)th fold.
Mean of scores over the folds.
Standard deviation of scores over the folds.
New in version 0.24.
Number of iterations run for the optimal alpha.
See also
The search for the optimal penalization parameter (alpha) is done on an iteratively refined grid: first the cross-validated scores on a grid are computed, then a new refined grid is centered around the maximum, and so on.
One of the challenges which is faced here is that the solvers can fail to converge to a well-conditioned estimate. The corresponding values of alpha then come out as missing values, but the optimum may be close to these missing values.
error_norm(comp_cov[, norm, scaling, squared])
Computes the Mean Squared Error between two covariance estimators.
fit(X[, y])
Fits the GraphicalLasso covariance model to X.
get_params([deep])
Get parameters for this estimator.
get_precision()
Getter for the precision matrix.
mahalanobis(X)
Computes the squared Mahalanobis distances of given observations.
score(X_test[, y])
Computes the log-likelihood of a Gaussian data set with self.covariance_ as an estimator of its covariance matrix.
set_params(**params)
Set the parameters of this estimator.
Computes the Mean Squared Error between two covariance estimators. (In the sense of the Frobenius norm).
The covariance to compare with.
The type of norm used to compute the error. Available error types: - ‘frobenius’ (default): sqrt(tr(A^t.A)) - ‘spectral’: sqrt(max(eigenvalues(A^t.A)) where A is the error (comp_cov - self.covariance_).
If True (default), the squared error norm is divided by n_features. If False, the squared error norm is not rescaled.
Whether to compute the squared error norm or the error norm. If True (default), the squared error norm is returned. If False, the error norm is returned.
The Mean Squared Error (in the sense of the Frobenius norm) between self and comp_cov covariance estimators.
Fits the GraphicalLasso covariance model to X.
Data from which to compute the covariance estimate
Not used, present for API consistency by convention.
Get parameters for this estimator.
If True, will return the parameters for this estimator and contained subobjects that are estimators.
Parameter names mapped to their values.
Getter for the precision matrix.
The precision matrix associated to the current covariance object.
Computes the squared Mahalanobis distances of given observations.
The observations, the Mahalanobis distances of the which we compute. Observations are assumed to be drawn from the same distribution than the data used in fit.
Squared Mahalanobis distances of the observations.
Computes the log-likelihood of a Gaussian data set with self.covariance_ as an estimator of its covariance matrix.
Test data of which we compute the likelihood, where n_samples is the number of samples and n_features is the number of features. X_test is assumed to be drawn from the same distribution than the data used in fit (including centering).
Not used, present for API consistency by convention.
The likelihood of the data set with self.covariance_ as an estimator of its covariance matrix.
Set the parameters of this estimator.
The method works on simple estimators as well as on nested objects (such as Pipeline). The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.
Estimator parameters.
Estimator instance.


Sparse inverse covariance w/ cross-validated choice of the l1 penalty.
See glossary entry for cross-validation estimator.
Read more in the User Guide.
Changed in version v0.20: GraphLassoCV has been renamed to GraphicalLassoCV
If an integer is given, it fixes the number of points on the grids of alpha to be used. If a list is given, it gives the grid to be used. See the notes in the class docstring for more details. Range is (0, inf] when floats given.
The number of times the grid is refined. Not used if explicit values of alphas are passed. Range is [1, inf).
Determines the cross-validation splitting strategy. Possible inputs for cv are:
For integer/None inputs KFold is used.
Refer User Guide for the various cross-validation strategies that can be used here.
Changed in version 0.20: cv default value if None changed from 3-fold to 5-fold.
The tolerance to declare convergence: if the dual gap goes below this value, iterations are stopped. Range is (0, inf].
The tolerance for the elastic net solver used to calculate the descent direction. This parameter controls the accuracy of the search direction for a given column update, not of the overall parameter estimate. Only used for mode=’cd’. Range is (0, inf].
Maximum number of iterations.
The Lasso solver to use: coordinate descent or LARS. Use LARS for very sparse underlying graphs, where number of features is greater than number of samples. Elsewhere prefer cd which is more numerically stable.
number of jobs to run in parallel. None means 1 unless in a joblib.parallel_backend context. -1 means using all processors. See Glossary for more details.
Changed in version v0.20: n_jobs default changed from 1 to None
If verbose is True, the objective function and duality gap are printed at each iteration.
If True, data are not centered before computation. Useful when working with data whose mean is almost, but not exactly zero. If False, data are centered before computation.
Estimated location, i.e. the estimated mean.
Estimated covariance matrix.
Estimated precision matrix (inverse covariance).
Penalization parameter selected.
All penalization parameters explored.
Deprecated since version 0.24: The cv_alphas_ attribute is deprecated in version 0.24 in favor of cv_results_['alphas'] and will be removed in version 1.1 (renaming of 0.26).
Log-likelihood score on left-out data across folds.
Deprecated since version 0.24: The grid_scores_ attribute is deprecated in version 0.24 in favor of cv_results_ and will be removed in version 1.1 (renaming of 0.26).
A dict with keys:
All penalization parameters explored.
Log-likelihood score on left-out data across (k)th fold.
Mean of scores over the folds.
Standard deviation of scores over the folds.
New in version 0.24.
Number of iterations run for the optimal alpha.
See also
The search for the optimal penalization parameter (alpha) is done on an iteratively refined grid: first the cross-validated scores on a grid are computed, then a new refined grid is centered around the maximum, and so on.
One of the challenges which is faced here is that the solvers can fail to converge to a well-conditioned estimate. The corresponding values of alpha then come out as missing values, but the optimum may be close to these missing values.
error_norm(comp_cov[, norm, scaling, squared])
Computes the Mean Squared Error between two covariance estimators.
fit(X[, y])
Fits the GraphicalLasso covariance model to X.
get_params([deep])
Get parameters for this estimator.
get_precision()
Getter for the precision matrix.
mahalanobis(X)
Computes the squared Mahalanobis distances of given observations.
score(X_test[, y])
Computes the log-likelihood of a Gaussian data set with self.covariance_ as an estimator of its covariance matrix.
set_params(**params)
Set the parameters of this estimator.
Computes the Mean Squared Error between two covariance estimators. (In the sense of the Frobenius norm).
The covariance to compare with.
The type of norm used to compute the error. Available error types: - ‘frobenius’ (default): sqrt(tr(A^t.A)) - ‘spectral’: sqrt(max(eigenvalues(A^t.A)) where A is the error (comp_cov - self.covariance_).
If True (default), the squared error norm is divided by n_features. If False, the squared error norm is not rescaled.
Whether to compute the squared error norm or the error norm. If True (default), the squared error norm is returned. If False, the error norm is returned.
The Mean Squared Error (in the sense of the Frobenius norm) between self and comp_cov covariance estimators.
Fits the GraphicalLasso covariance model to X.
Data from which to compute the covariance estimate
Not used, present for API consistency by convention.
Get parameters for this estimator.
If True, will return the parameters for this estimator and contained subobjects that are estimators.
Parameter names mapped to their values.
Getter for the precision matrix.
The precision matrix associated to the current covariance object.
Computes the squared Mahalanobis distances of given observations.
The observations, the Mahalanobis distances of the which we compute. Observations are assumed to be drawn from the same distribution than the data used in fit.
Squared Mahalanobis distances of the observations.
Computes the log-likelihood of a Gaussian data set with self.covariance_ as an estimator of its covariance matrix.
Test data of which we compute the likelihood, where n_samples is the number of samples and n_features is the number of features. X_test is assumed to be drawn from the same distribution than the data used in fit (including centering).
Not used, present for API consistency by convention.
The likelihood of the data set with self.covariance_ as an estimator of its covariance matrix.
Set the parameters of this estimator.
The method works on simple estimators as well as on nested objects (such as Pipeline). The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.
Estimator parameters.
Estimator instance.
Sparse inverse covariance estimation
Visualizing the stock market structure


Fits the GraphicalLasso covariance model to X.
Data from which to compute the covariance estimate
Not used, present for API consistency by convention.


l1-penalized covariance estimator
Read more in the User Guide.
Changed in version v0.20: graph_lasso has been renamed to graphical_lasso
Empirical covariance from which to compute the covariance estimate.
The regularization parameter: the higher alpha, the more regularization, the sparser the inverse covariance. Range is (0, inf].
The initial guess for the covariance. If None, then the empirical covariance is used.
The Lasso solver to use: coordinate descent or LARS. Use LARS for very sparse underlying graphs, where p > n. Elsewhere prefer cd which is more numerically stable.
The tolerance to declare convergence: if the dual gap goes below this value, iterations are stopped. Range is (0, inf].
The tolerance for the elastic net solver used to calculate the descent direction. This parameter controls the accuracy of the search direction for a given column update, not of the overall parameter estimate. Only used for mode=’cd’. Range is (0, inf].
The maximum number of iterations.
If verbose is True, the objective function and dual gap are printed at each iteration.
If return_costs is True, the objective function and dual gap at each iteration are returned.
The machine-precision regularization in the computation of the Cholesky diagonal factors. Increase this for very ill-conditioned systems. Default is np.finfo(np.float64).eps.
Whether or not to return the number of iterations.
The estimated covariance matrix.
The estimated (sparse) precision matrix.
The list of values of the objective function and the dual gap at each iteration. Returned only if return_costs is True.
Number of iterations. Returned only if return_n_iter is set to True.
See also
The algorithm employed to solve this problem is the GLasso algorithm, from the Friedman 2008 Biostatistics paper. It is the same algorithm as in the R glasso package.
One possible difference with the glasso R package is that the diagonal coefficients are not penalized.


LedoitWolf Estimator
Ledoit-Wolf is a particular form of shrinkage, where the shrinkage coefficient is computed using O. Ledoit and M. Wolf’s formula as described in “A Well-Conditioned Estimator for Large-Dimensional Covariance Matrices”, Ledoit and Wolf, Journal of Multivariate Analysis, Volume 88, Issue 2, February 2004, pages 365-411.
Read more in the User Guide.
Specify if the estimated precision is stored.
If True, data will not be centered before computation. Useful when working with data whose mean is almost, but not exactly zero. If False (default), data will be centered before computation.
Size of blocks into which the covariance matrix will be split during its Ledoit-Wolf estimation. This is purely a memory optimization and does not affect results.
Estimated covariance matrix.
Estimated location, i.e. the estimated mean.
Estimated pseudo inverse matrix. (stored only if store_precision is True)
Coefficient in the convex combination used for the computation of the shrunk estimate. Range is [0, 1].
The regularised covariance is:
(1 - shrinkage) * cov + shrinkage * mu * np.identity(n_features)
where mu = trace(cov) / n_features and shrinkage is given by the Ledoit and Wolf formula (see References)
“A Well-Conditioned Estimator for Large-Dimensional Covariance Matrices”, Ledoit and Wolf, Journal of Multivariate Analysis, Volume 88, Issue 2, February 2004, pages 365-411.
error_norm(comp_cov[, norm, scaling, squared])
Computes the Mean Squared Error between two covariance estimators.
fit(X[, y])
Fit the Ledoit-Wolf shrunk covariance model according to the given training data and parameters.
get_params([deep])
Get parameters for this estimator.
get_precision()
Getter for the precision matrix.
mahalanobis(X)
Computes the squared Mahalanobis distances of given observations.
score(X_test[, y])
Computes the log-likelihood of a Gaussian data set with self.covariance_ as an estimator of its covariance matrix.
set_params(**params)
Set the parameters of this estimator.
Computes the Mean Squared Error between two covariance estimators. (In the sense of the Frobenius norm).
The covariance to compare with.
The type of norm used to compute the error. Available error types: - ‘frobenius’ (default): sqrt(tr(A^t.A)) - ‘spectral’: sqrt(max(eigenvalues(A^t.A)) where A is the error (comp_cov - self.covariance_).
If True (default), the squared error norm is divided by n_features. If False, the squared error norm is not rescaled.
Whether to compute the squared error norm or the error norm. If True (default), the squared error norm is returned. If False, the error norm is returned.
The Mean Squared Error (in the sense of the Frobenius norm) between self and comp_cov covariance estimators.
Fit the Ledoit-Wolf shrunk covariance model according to the given training data and parameters.
Training data, where n_samples is the number of samples and n_features is the number of features.
Not used, present for API consistency by convention.
Get parameters for this estimator.
If True, will return the parameters for this estimator and contained subobjects that are estimators.
Parameter names mapped to their values.
Getter for the precision matrix.
The precision matrix associated to the current covariance object.
Computes the squared Mahalanobis distances of given observations.
The observations, the Mahalanobis distances of the which we compute. Observations are assumed to be drawn from the same distribution than the data used in fit.
Squared Mahalanobis distances of the observations.
Computes the log-likelihood of a Gaussian data set with self.covariance_ as an estimator of its covariance matrix.
Test data of which we compute the likelihood, where n_samples is the number of samples and n_features is the number of features. X_test is assumed to be drawn from the same distribution than the data used in fit (including centering).
Not used, present for API consistency by convention.
The likelihood of the data set with self.covariance_ as an estimator of its covariance matrix.
Set the parameters of this estimator.
The method works on simple estimators as well as on nested objects (such as Pipeline). The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.
Estimator parameters.
Estimator instance.


LedoitWolf Estimator
Ledoit-Wolf is a particular form of shrinkage, where the shrinkage coefficient is computed using O. Ledoit and M. Wolf’s formula as described in “A Well-Conditioned Estimator for Large-Dimensional Covariance Matrices”, Ledoit and Wolf, Journal of Multivariate Analysis, Volume 88, Issue 2, February 2004, pages 365-411.
Read more in the User Guide.
Specify if the estimated precision is stored.
If True, data will not be centered before computation. Useful when working with data whose mean is almost, but not exactly zero. If False (default), data will be centered before computation.
Size of blocks into which the covariance matrix will be split during its Ledoit-Wolf estimation. This is purely a memory optimization and does not affect results.
Estimated covariance matrix.
Estimated location, i.e. the estimated mean.
Estimated pseudo inverse matrix. (stored only if store_precision is True)
Coefficient in the convex combination used for the computation of the shrunk estimate. Range is [0, 1].
The regularised covariance is:
(1 - shrinkage) * cov + shrinkage * mu * np.identity(n_features)
where mu = trace(cov) / n_features and shrinkage is given by the Ledoit and Wolf formula (see References)
“A Well-Conditioned Estimator for Large-Dimensional Covariance Matrices”, Ledoit and Wolf, Journal of Multivariate Analysis, Volume 88, Issue 2, February 2004, pages 365-411.
error_norm(comp_cov[, norm, scaling, squared])
Computes the Mean Squared Error between two covariance estimators.
fit(X[, y])
Fit the Ledoit-Wolf shrunk covariance model according to the given training data and parameters.
get_params([deep])
Get parameters for this estimator.
get_precision()
Getter for the precision matrix.
mahalanobis(X)
Computes the squared Mahalanobis distances of given observations.
score(X_test[, y])
Computes the log-likelihood of a Gaussian data set with self.covariance_ as an estimator of its covariance matrix.
set_params(**params)
Set the parameters of this estimator.
Computes the Mean Squared Error between two covariance estimators. (In the sense of the Frobenius norm).
The covariance to compare with.
The type of norm used to compute the error. Available error types: - ‘frobenius’ (default): sqrt(tr(A^t.A)) - ‘spectral’: sqrt(max(eigenvalues(A^t.A)) where A is the error (comp_cov - self.covariance_).
If True (default), the squared error norm is divided by n_features. If False, the squared error norm is not rescaled.
Whether to compute the squared error norm or the error norm. If True (default), the squared error norm is returned. If False, the error norm is returned.
The Mean Squared Error (in the sense of the Frobenius norm) between self and comp_cov covariance estimators.
Fit the Ledoit-Wolf shrunk covariance model according to the given training data and parameters.
Training data, where n_samples is the number of samples and n_features is the number of features.
Not used, present for API consistency by convention.
Get parameters for this estimator.
If True, will return the parameters for this estimator and contained subobjects that are estimators.
Parameter names mapped to their values.
Getter for the precision matrix.
The precision matrix associated to the current covariance object.
Computes the squared Mahalanobis distances of given observations.
The observations, the Mahalanobis distances of the which we compute. Observations are assumed to be drawn from the same distribution than the data used in fit.
Squared Mahalanobis distances of the observations.
Computes the log-likelihood of a Gaussian data set with self.covariance_ as an estimator of its covariance matrix.
Test data of which we compute the likelihood, where n_samples is the number of samples and n_features is the number of features. X_test is assumed to be drawn from the same distribution than the data used in fit (including centering).
Not used, present for API consistency by convention.
The likelihood of the data set with self.covariance_ as an estimator of its covariance matrix.
Set the parameters of this estimator.
The method works on simple estimators as well as on nested objects (such as Pipeline). The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.
Estimator parameters.
Estimator instance.
Ledoit-Wolf vs OAS estimation
Shrinkage covariance estimation: LedoitWolf vs OAS and max-likelihood
Model selection with Probabilistic PCA and Factor Analysis (FA)


Fit the Ledoit-Wolf shrunk covariance model according to the given training data and parameters.
Training data, where n_samples is the number of samples and n_features is the number of features.
Not used, present for API consistency by convention.


Estimates the shrunk Ledoit-Wolf covariance matrix.
Read more in the User Guide.
Data from which to compute the covariance estimate
If True, data will not be centered before computation. Useful to work with data whose mean is significantly equal to zero but is not exactly zero. If False, data will be centered before computation.
Size of blocks into which the covariance matrix will be split. This is purely a memory optimization and does not affect results.
Shrunk covariance.
Coefficient in the convex combination used for the computation of the shrunk estimate.
The regularized (shrunk) covariance is:
(1 - shrinkage) * cov + shrinkage * mu * np.identity(n_features)
where mu = trace(cov) / n_features


Minimum Covariance Determinant (MCD): robust estimator of covariance.
The Minimum Covariance Determinant covariance estimator is to be applied on Gaussian-distributed data, but could still be relevant on data drawn from a unimodal, symmetric distribution. It is not meant to be used with multi-modal data (the algorithm used to fit a MinCovDet object is likely to fail in such a case). One should consider projection pursuit methods to deal with multi-modal datasets.
Read more in the User Guide.
Specify if the estimated precision is stored.
If True, the support of the robust location and the covariance estimates is computed, and a covariance estimate is recomputed from it, without centering the data. Useful to work with data whose mean is significantly equal to zero but is not exactly zero. If False, the robust location and covariance are directly computed with the FastMCD algorithm without additional treatment.
The proportion of points to be included in the support of the raw MCD estimate. Default is None, which implies that the minimum value of support_fraction will be used within the algorithm: (n_sample + n_features + 1) / 2. The parameter must be in the range (0, 1).
Determines the pseudo random number generator for shuffling the data. Pass an int for reproducible results across multiple function calls. See :term: Glossary <random_state>.
The raw robust estimated location before correction and re-weighting.
The raw robust estimated covariance before correction and re-weighting.
A mask of the observations that have been used to compute the raw robust estimates of location and shape, before correction and re-weighting.
Estimated robust location.
Estimated robust covariance matrix.
Estimated pseudo inverse matrix. (stored only if store_precision is True)
A mask of the observations that have been used to compute the robust estimates of location and shape.
Mahalanobis distances of the training set (on which fit is called) observations.
P. J. Rousseeuw. Least median of squares regression. J. Am Stat Ass, 79:871, 1984.
A Fast Algorithm for the Minimum Covariance Determinant Estimator, 1999, American Statistical Association and the American Society for Quality, TECHNOMETRICS
R. W. Butler, P. L. Davies and M. Jhun, Asymptotics For The Minimum Covariance Determinant Estimator, The Annals of Statistics, 1993, Vol. 21, No. 3, 1385-1400
correct_covariance(data)
Apply a correction to raw Minimum Covariance Determinant estimates.
error_norm(comp_cov[, norm, scaling, squared])
Computes the Mean Squared Error between two covariance estimators.
fit(X[, y])
Fits a Minimum Covariance Determinant with the FastMCD algorithm.
get_params([deep])
Get parameters for this estimator.
get_precision()
Getter for the precision matrix.
mahalanobis(X)
Computes the squared Mahalanobis distances of given observations.
reweight_covariance(data)
Re-weight raw Minimum Covariance Determinant estimates.
score(X_test[, y])
Computes the log-likelihood of a Gaussian data set with self.covariance_ as an estimator of its covariance matrix.
set_params(**params)
Set the parameters of this estimator.
Apply a correction to raw Minimum Covariance Determinant estimates.
Correction using the empirical correction factor suggested by Rousseeuw and Van Driessen in [RVD].
The data matrix, with p features and n samples. The data set must be the one which was used to compute the raw estimates.
Corrected robust covariance estimate.
A Fast Algorithm for the Minimum Covariance Determinant Estimator, 1999, American Statistical Association and the American Society for Quality, TECHNOMETRICS
Computes the Mean Squared Error between two covariance estimators. (In the sense of the Frobenius norm).
The covariance to compare with.
The type of norm used to compute the error. Available error types: - ‘frobenius’ (default): sqrt(tr(A^t.A)) - ‘spectral’: sqrt(max(eigenvalues(A^t.A)) where A is the error (comp_cov - self.covariance_).
If True (default), the squared error norm is divided by n_features. If False, the squared error norm is not rescaled.
Whether to compute the squared error norm or the error norm. If True (default), the squared error norm is returned. If False, the error norm is returned.
The Mean Squared Error (in the sense of the Frobenius norm) between self and comp_cov covariance estimators.
Fits a Minimum Covariance Determinant with the FastMCD algorithm.
Training data, where n_samples is the number of samples and n_features is the number of features.
Not used, present for API consistency by convention.
Get parameters for this estimator.
If True, will return the parameters for this estimator and contained subobjects that are estimators.
Parameter names mapped to their values.
Getter for the precision matrix.
The precision matrix associated to the current covariance object.
Computes the squared Mahalanobis distances of given observations.
The observations, the Mahalanobis distances of the which we compute. Observations are assumed to be drawn from the same distribution than the data used in fit.
Squared Mahalanobis distances of the observations.
Re-weight raw Minimum Covariance Determinant estimates.
Re-weight observations using Rousseeuw’s method (equivalent to deleting outlying observations from the data set before computing location and covariance estimates) described in [RVDriessen].
The data matrix, with p features and n samples. The data set must be the one which was used to compute the raw estimates.
Re-weighted robust location estimate.
Re-weighted robust covariance estimate.
A mask of the observations that have been used to compute the re-weighted robust location and covariance estimates.
A Fast Algorithm for the Minimum Covariance Determinant Estimator, 1999, American Statistical Association and the American Society for Quality, TECHNOMETRICS
Computes the log-likelihood of a Gaussian data set with self.covariance_ as an estimator of its covariance matrix.
Test data of which we compute the likelihood, where n_samples is the number of samples and n_features is the number of features. X_test is assumed to be drawn from the same distribution than the data used in fit (including centering).
Not used, present for API consistency by convention.
The likelihood of the data set with self.covariance_ as an estimator of its covariance matrix.
Set the parameters of this estimator.
The method works on simple estimators as well as on nested objects (such as Pipeline). The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.
Estimator parameters.
Estimator instance.


Minimum Covariance Determinant (MCD): robust estimator of covariance.
The Minimum Covariance Determinant covariance estimator is to be applied on Gaussian-distributed data, but could still be relevant on data drawn from a unimodal, symmetric distribution. It is not meant to be used with multi-modal data (the algorithm used to fit a MinCovDet object is likely to fail in such a case). One should consider projection pursuit methods to deal with multi-modal datasets.
Read more in the User Guide.
Specify if the estimated precision is stored.
If True, the support of the robust location and the covariance estimates is computed, and a covariance estimate is recomputed from it, without centering the data. Useful to work with data whose mean is significantly equal to zero but is not exactly zero. If False, the robust location and covariance are directly computed with the FastMCD algorithm without additional treatment.
The proportion of points to be included in the support of the raw MCD estimate. Default is None, which implies that the minimum value of support_fraction will be used within the algorithm: (n_sample + n_features + 1) / 2. The parameter must be in the range (0, 1).
Determines the pseudo random number generator for shuffling the data. Pass an int for reproducible results across multiple function calls. See :term: Glossary <random_state>.
The raw robust estimated location before correction and re-weighting.
The raw robust estimated covariance before correction and re-weighting.
A mask of the observations that have been used to compute the raw robust estimates of location and shape, before correction and re-weighting.
Estimated robust location.
Estimated robust covariance matrix.
Estimated pseudo inverse matrix. (stored only if store_precision is True)
A mask of the observations that have been used to compute the robust estimates of location and shape.
Mahalanobis distances of the training set (on which fit is called) observations.
P. J. Rousseeuw. Least median of squares regression. J. Am Stat Ass, 79:871, 1984.
A Fast Algorithm for the Minimum Covariance Determinant Estimator, 1999, American Statistical Association and the American Society for Quality, TECHNOMETRICS
R. W. Butler, P. L. Davies and M. Jhun, Asymptotics For The Minimum Covariance Determinant Estimator, The Annals of Statistics, 1993, Vol. 21, No. 3, 1385-1400
correct_covariance(data)
Apply a correction to raw Minimum Covariance Determinant estimates.
error_norm(comp_cov[, norm, scaling, squared])
Computes the Mean Squared Error between two covariance estimators.
fit(X[, y])
Fits a Minimum Covariance Determinant with the FastMCD algorithm.
get_params([deep])
Get parameters for this estimator.
get_precision()
Getter for the precision matrix.
mahalanobis(X)
Computes the squared Mahalanobis distances of given observations.
reweight_covariance(data)
Re-weight raw Minimum Covariance Determinant estimates.
score(X_test[, y])
Computes the log-likelihood of a Gaussian data set with self.covariance_ as an estimator of its covariance matrix.
set_params(**params)
Set the parameters of this estimator.
Apply a correction to raw Minimum Covariance Determinant estimates.
Correction using the empirical correction factor suggested by Rousseeuw and Van Driessen in [RVD].
The data matrix, with p features and n samples. The data set must be the one which was used to compute the raw estimates.
Corrected robust covariance estimate.
A Fast Algorithm for the Minimum Covariance Determinant Estimator, 1999, American Statistical Association and the American Society for Quality, TECHNOMETRICS
Computes the Mean Squared Error between two covariance estimators. (In the sense of the Frobenius norm).
The covariance to compare with.
The type of norm used to compute the error. Available error types: - ‘frobenius’ (default): sqrt(tr(A^t.A)) - ‘spectral’: sqrt(max(eigenvalues(A^t.A)) where A is the error (comp_cov - self.covariance_).
If True (default), the squared error norm is divided by n_features. If False, the squared error norm is not rescaled.
Whether to compute the squared error norm or the error norm. If True (default), the squared error norm is returned. If False, the error norm is returned.
The Mean Squared Error (in the sense of the Frobenius norm) between self and comp_cov covariance estimators.
Fits a Minimum Covariance Determinant with the FastMCD algorithm.
Training data, where n_samples is the number of samples and n_features is the number of features.
Not used, present for API consistency by convention.
Get parameters for this estimator.
If True, will return the parameters for this estimator and contained subobjects that are estimators.
Parameter names mapped to their values.
Getter for the precision matrix.
The precision matrix associated to the current covariance object.
Computes the squared Mahalanobis distances of given observations.
The observations, the Mahalanobis distances of the which we compute. Observations are assumed to be drawn from the same distribution than the data used in fit.
Squared Mahalanobis distances of the observations.
Re-weight raw Minimum Covariance Determinant estimates.
Re-weight observations using Rousseeuw’s method (equivalent to deleting outlying observations from the data set before computing location and covariance estimates) described in [RVDriessen].
The data matrix, with p features and n samples. The data set must be the one which was used to compute the raw estimates.
Re-weighted robust location estimate.
Re-weighted robust covariance estimate.
A mask of the observations that have been used to compute the re-weighted robust location and covariance estimates.
A Fast Algorithm for the Minimum Covariance Determinant Estimator, 1999, American Statistical Association and the American Society for Quality, TECHNOMETRICS
Computes the log-likelihood of a Gaussian data set with self.covariance_ as an estimator of its covariance matrix.
Test data of which we compute the likelihood, where n_samples is the number of samples and n_features is the number of features. X_test is assumed to be drawn from the same distribution than the data used in fit (including centering).
Not used, present for API consistency by convention.
The likelihood of the data set with self.covariance_ as an estimator of its covariance matrix.
Set the parameters of this estimator.
The method works on simple estimators as well as on nested objects (such as Pipeline). The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.
Estimator parameters.
Estimator instance.
Robust covariance estimation and Mahalanobis distances relevance
Robust vs Empirical covariance estimate


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


Fits a Minimum Covariance Determinant with the FastMCD algorithm.
Training data, where n_samples is the number of samples and n_features is the number of features.
Not used, present for API consistency by convention.


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


Computes the log-likelihood of a Gaussian data set with self.covariance_ as an estimator of its covariance matrix.
Test data of which we compute the likelihood, where n_samples is the number of samples and n_features is the number of features. X_test is assumed to be drawn from the same distribution than the data used in fit (including centering).
Not used, present for API consistency by convention.
The likelihood of the data set with self.covariance_ as an estimator of its covariance matrix.


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


Oracle Approximating Shrinkage Estimator
Read more in the User Guide.
OAS is a particular form of shrinkage described in “Shrinkage Algorithms for MMSE Covariance Estimation” Chen et al., IEEE Trans. on Sign. Proc., Volume 58, Issue 10, October 2010.
The formula used here does not correspond to the one given in the article. In the original article, formula (23) states that 2/p is multiplied by Trace(cov*cov) in both the numerator and denominator, but this operation is omitted because for a large p, the value of 2/p is so small that it doesn’t affect the value of the estimator.
Specify if the estimated precision is stored.
If True, data will not be centered before computation. Useful when working with data whose mean is almost, but not exactly zero. If False (default), data will be centered before computation.
Estimated covariance matrix.
Estimated location, i.e. the estimated mean.
Estimated pseudo inverse matrix. (stored only if store_precision is True)
coefficient in the convex combination used for the computation of the shrunk estimate. Range is [0, 1].
The regularised covariance is:
(1 - shrinkage) * cov + shrinkage * mu * np.identity(n_features)
where mu = trace(cov) / n_features and shrinkage is given by the OAS formula (see References)
“Shrinkage Algorithms for MMSE Covariance Estimation” Chen et al., IEEE Trans. on Sign. Proc., Volume 58, Issue 10, October 2010.
error_norm(comp_cov[, norm, scaling, squared])
Computes the Mean Squared Error between two covariance estimators.
fit(X[, y])
Fit the Oracle Approximating Shrinkage covariance model according to the given training data and parameters.
get_params([deep])
Get parameters for this estimator.
get_precision()
Getter for the precision matrix.
mahalanobis(X)
Computes the squared Mahalanobis distances of given observations.
score(X_test[, y])
Computes the log-likelihood of a Gaussian data set with self.covariance_ as an estimator of its covariance matrix.
set_params(**params)
Set the parameters of this estimator.
Computes the Mean Squared Error between two covariance estimators. (In the sense of the Frobenius norm).
The covariance to compare with.
The type of norm used to compute the error. Available error types: - ‘frobenius’ (default): sqrt(tr(A^t.A)) - ‘spectral’: sqrt(max(eigenvalues(A^t.A)) where A is the error (comp_cov - self.covariance_).
If True (default), the squared error norm is divided by n_features. If False, the squared error norm is not rescaled.
Whether to compute the squared error norm or the error norm. If True (default), the squared error norm is returned. If False, the error norm is returned.
The Mean Squared Error (in the sense of the Frobenius norm) between self and comp_cov covariance estimators.
Fit the Oracle Approximating Shrinkage covariance model according to the given training data and parameters.
Training data, where n_samples is the number of samples and n_features is the number of features.
Not used, present for API consistency by convention.
Get parameters for this estimator.
If True, will return the parameters for this estimator and contained subobjects that are estimators.
Parameter names mapped to their values.
Getter for the precision matrix.
The precision matrix associated to the current covariance object.
Computes the squared Mahalanobis distances of given observations.
The observations, the Mahalanobis distances of the which we compute. Observations are assumed to be drawn from the same distribution than the data used in fit.
Squared Mahalanobis distances of the observations.
Computes the log-likelihood of a Gaussian data set with self.covariance_ as an estimator of its covariance matrix.
Test data of which we compute the likelihood, where n_samples is the number of samples and n_features is the number of features. X_test is assumed to be drawn from the same distribution than the data used in fit (including centering).
Not used, present for API consistency by convention.
The likelihood of the data set with self.covariance_ as an estimator of its covariance matrix.
Set the parameters of this estimator.
The method works on simple estimators as well as on nested objects (such as Pipeline). The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.
Estimator parameters.
Estimator instance.


Estimate covariance with the Oracle Approximating Shrinkage algorithm.
Data from which to compute the covariance estimate.
If True, data will not be centered before computation. Useful to work with data whose mean is significantly equal to zero but is not exactly zero. If False, data will be centered before computation.
Shrunk covariance.
Coefficient in the convex combination used for the computation of the shrunk estimate.
The regularised (shrunk) covariance is:
(1 - shrinkage) * cov + shrinkage * mu * np.identity(n_features)
where mu = trace(cov) / n_features
The formula we used to implement the OAS is slightly modified compared to the one given in the article. See OAS for more details.


Oracle Approximating Shrinkage Estimator
Read more in the User Guide.
OAS is a particular form of shrinkage described in “Shrinkage Algorithms for MMSE Covariance Estimation” Chen et al., IEEE Trans. on Sign. Proc., Volume 58, Issue 10, October 2010.
The formula used here does not correspond to the one given in the article. In the original article, formula (23) states that 2/p is multiplied by Trace(cov*cov) in both the numerator and denominator, but this operation is omitted because for a large p, the value of 2/p is so small that it doesn’t affect the value of the estimator.
Specify if the estimated precision is stored.
If True, data will not be centered before computation. Useful when working with data whose mean is almost, but not exactly zero. If False (default), data will be centered before computation.
Estimated covariance matrix.
Estimated location, i.e. the estimated mean.
Estimated pseudo inverse matrix. (stored only if store_precision is True)
coefficient in the convex combination used for the computation of the shrunk estimate. Range is [0, 1].
The regularised covariance is:
(1 - shrinkage) * cov + shrinkage * mu * np.identity(n_features)
where mu = trace(cov) / n_features and shrinkage is given by the OAS formula (see References)
“Shrinkage Algorithms for MMSE Covariance Estimation” Chen et al., IEEE Trans. on Sign. Proc., Volume 58, Issue 10, October 2010.
error_norm(comp_cov[, norm, scaling, squared])
Computes the Mean Squared Error between two covariance estimators.
fit(X[, y])
Fit the Oracle Approximating Shrinkage covariance model according to the given training data and parameters.
get_params([deep])
Get parameters for this estimator.
get_precision()
Getter for the precision matrix.
mahalanobis(X)
Computes the squared Mahalanobis distances of given observations.
score(X_test[, y])
Computes the log-likelihood of a Gaussian data set with self.covariance_ as an estimator of its covariance matrix.
set_params(**params)
Set the parameters of this estimator.
Computes the Mean Squared Error between two covariance estimators. (In the sense of the Frobenius norm).
The covariance to compare with.
The type of norm used to compute the error. Available error types: - ‘frobenius’ (default): sqrt(tr(A^t.A)) - ‘spectral’: sqrt(max(eigenvalues(A^t.A)) where A is the error (comp_cov - self.covariance_).
If True (default), the squared error norm is divided by n_features. If False, the squared error norm is not rescaled.
Whether to compute the squared error norm or the error norm. If True (default), the squared error norm is returned. If False, the error norm is returned.
The Mean Squared Error (in the sense of the Frobenius norm) between self and comp_cov covariance estimators.
Fit the Oracle Approximating Shrinkage covariance model according to the given training data and parameters.
Training data, where n_samples is the number of samples and n_features is the number of features.
Not used, present for API consistency by convention.
Get parameters for this estimator.
If True, will return the parameters for this estimator and contained subobjects that are estimators.
Parameter names mapped to their values.
Getter for the precision matrix.
The precision matrix associated to the current covariance object.
Computes the squared Mahalanobis distances of given observations.
The observations, the Mahalanobis distances of the which we compute. Observations are assumed to be drawn from the same distribution than the data used in fit.
Squared Mahalanobis distances of the observations.
Computes the log-likelihood of a Gaussian data set with self.covariance_ as an estimator of its covariance matrix.
Test data of which we compute the likelihood, where n_samples is the number of samples and n_features is the number of features. X_test is assumed to be drawn from the same distribution than the data used in fit (including centering).
Not used, present for API consistency by convention.
The likelihood of the data set with self.covariance_ as an estimator of its covariance matrix.
Set the parameters of this estimator.
The method works on simple estimators as well as on nested objects (such as Pipeline). The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.
Estimator parameters.
Estimator instance.
Normal, Ledoit-Wolf and OAS Linear Discriminant Analysis for classification
Ledoit-Wolf vs OAS estimation
Shrinkage covariance estimation: LedoitWolf vs OAS and max-likelihood


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


Fit the Oracle Approximating Shrinkage covariance model according to the given training data and parameters.
Training data, where n_samples is the number of samples and n_features is the number of features.
Not used, present for API consistency by convention.


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


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


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


Covariance estimator with shrinkage
Read more in the User Guide.
Specify if the estimated precision is stored
If True, data will not be centered before computation. Useful when working with data whose mean is almost, but not exactly zero. If False, data will be centered before computation.
Coefficient in the convex combination used for the computation of the shrunk estimate. Range is [0, 1].
Estimated covariance matrix
Estimated location, i.e. the estimated mean.
Estimated pseudo inverse matrix. (stored only if store_precision is True)
The regularized covariance is given by:
(1 - shrinkage) * cov + shrinkage * mu * np.identity(n_features)
where mu = trace(cov) / n_features
error_norm(comp_cov[, norm, scaling, squared])
Computes the Mean Squared Error between two covariance estimators.
fit(X[, y])
Fit the shrunk covariance model according to the given training data and parameters.
get_params([deep])
Get parameters for this estimator.
get_precision()
Getter for the precision matrix.
mahalanobis(X)
Computes the squared Mahalanobis distances of given observations.
score(X_test[, y])
Computes the log-likelihood of a Gaussian data set with self.covariance_ as an estimator of its covariance matrix.
set_params(**params)
Set the parameters of this estimator.
Computes the Mean Squared Error between two covariance estimators. (In the sense of the Frobenius norm).
The covariance to compare with.
The type of norm used to compute the error. Available error types: - ‘frobenius’ (default): sqrt(tr(A^t.A)) - ‘spectral’: sqrt(max(eigenvalues(A^t.A)) where A is the error (comp_cov - self.covariance_).
If True (default), the squared error norm is divided by n_features. If False, the squared error norm is not rescaled.
Whether to compute the squared error norm or the error norm. If True (default), the squared error norm is returned. If False, the error norm is returned.
The Mean Squared Error (in the sense of the Frobenius norm) between self and comp_cov covariance estimators.
Fit the shrunk covariance model according to the given training data and parameters.
Training data, where n_samples is the number of samples and n_features is the number of features.
Not used, present for API consistency by convention.
Get parameters for this estimator.
If True, will return the parameters for this estimator and contained subobjects that are estimators.
Parameter names mapped to their values.
Getter for the precision matrix.
The precision matrix associated to the current covariance object.
Computes the squared Mahalanobis distances of given observations.
The observations, the Mahalanobis distances of the which we compute. Observations are assumed to be drawn from the same distribution than the data used in fit.
Squared Mahalanobis distances of the observations.
Computes the log-likelihood of a Gaussian data set with self.covariance_ as an estimator of its covariance matrix.
Test data of which we compute the likelihood, where n_samples is the number of samples and n_features is the number of features. X_test is assumed to be drawn from the same distribution than the data used in fit (including centering).
Not used, present for API consistency by convention.
The likelihood of the data set with self.covariance_ as an estimator of its covariance matrix.
Set the parameters of this estimator.
The method works on simple estimators as well as on nested objects (such as Pipeline). The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.
Estimator parameters.
Estimator instance.


Covariance estimator with shrinkage
Read more in the User Guide.
Specify if the estimated precision is stored
If True, data will not be centered before computation. Useful when working with data whose mean is almost, but not exactly zero. If False, data will be centered before computation.
Coefficient in the convex combination used for the computation of the shrunk estimate. Range is [0, 1].
Estimated covariance matrix
Estimated location, i.e. the estimated mean.
Estimated pseudo inverse matrix. (stored only if store_precision is True)
The regularized covariance is given by:
(1 - shrinkage) * cov + shrinkage * mu * np.identity(n_features)
where mu = trace(cov) / n_features
error_norm(comp_cov[, norm, scaling, squared])
Computes the Mean Squared Error between two covariance estimators.
fit(X[, y])
Fit the shrunk covariance model according to the given training data and parameters.
get_params([deep])
Get parameters for this estimator.
get_precision()
Getter for the precision matrix.
mahalanobis(X)
Computes the squared Mahalanobis distances of given observations.
score(X_test[, y])
Computes the log-likelihood of a Gaussian data set with self.covariance_ as an estimator of its covariance matrix.
set_params(**params)
Set the parameters of this estimator.
Computes the Mean Squared Error between two covariance estimators. (In the sense of the Frobenius norm).
The covariance to compare with.
The type of norm used to compute the error. Available error types: - ‘frobenius’ (default): sqrt(tr(A^t.A)) - ‘spectral’: sqrt(max(eigenvalues(A^t.A)) where A is the error (comp_cov - self.covariance_).
If True (default), the squared error norm is divided by n_features. If False, the squared error norm is not rescaled.
Whether to compute the squared error norm or the error norm. If True (default), the squared error norm is returned. If False, the error norm is returned.
The Mean Squared Error (in the sense of the Frobenius norm) between self and comp_cov covariance estimators.
Fit the shrunk covariance model according to the given training data and parameters.
Training data, where n_samples is the number of samples and n_features is the number of features.
Not used, present for API consistency by convention.
Get parameters for this estimator.
If True, will return the parameters for this estimator and contained subobjects that are estimators.
Parameter names mapped to their values.
Getter for the precision matrix.
The precision matrix associated to the current covariance object.
Computes the squared Mahalanobis distances of given observations.
The observations, the Mahalanobis distances of the which we compute. Observations are assumed to be drawn from the same distribution than the data used in fit.
Squared Mahalanobis distances of the observations.
Computes the log-likelihood of a Gaussian data set with self.covariance_ as an estimator of its covariance matrix.
Test data of which we compute the likelihood, where n_samples is the number of samples and n_features is the number of features. X_test is assumed to be drawn from the same distribution than the data used in fit (including centering).
Not used, present for API consistency by convention.
The likelihood of the data set with self.covariance_ as an estimator of its covariance matrix.
Set the parameters of this estimator.
The method works on simple estimators as well as on nested objects (such as Pipeline). The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.
Estimator parameters.
Estimator instance.
Shrinkage covariance estimation: LedoitWolf vs OAS and max-likelihood
Model selection with Probabilistic PCA and Factor Analysis (FA)


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


Calculates a covariance matrix shrunk on the diagonal
Read more in the User Guide.
Covariance matrix to be shrunk
Coefficient in the convex combination used for the computation of the shrunk estimate. Range is [0, 1].
Shrunk covariance.
The regularized (shrunk) covariance is given by:
(1 - shrinkage) * cov + shrinkage * mu * np.identity(n_features)
where mu = trace(cov) / n_features


Canonical Correlation Analysis, also known as “Mode B” PLS.
Read more in the User Guide.
Number of components to keep. Should be in [1, min(n_samples,
n_features, n_targets)].
Whether to scale X and Y.
the maximum number of iterations of the power method.
The tolerance used as convergence criteria in the power method: the algorithm stops whenever the squared norm of u_i - u_{i-1} is less than tol, where u corresponds to the left singular vector.
Whether to copy X and Y in fit before applying centering, and potentially scaling. If False, these operations will be done inplace, modifying both arrays.
The left singular vectors of the cross-covariance matrices of each iteration.
The right singular vectors of the cross-covariance matrices of each iteration.
The loadings of X.
The loadings of Y.
The transformed training samples.
Deprecated since version 0.24: x_scores_ is deprecated in 0.24 and will be removed in 1.1 (renaming of 0.26). You can just call transform on the training data instead.
The transformed training targets.
Deprecated since version 0.24: y_scores_ is deprecated in 0.24 and will be removed in 1.1 (renaming of 0.26). You can just call transform on the training data instead.
The projection matrix used to transform X.
The projection matrix used to transform Y.
The coefficients of the linear model such that Y is approximated as Y = X @ coef_.
Number of iterations of the power method, for each component.
See also
fit(X, Y)
Fit model to data.
fit_transform(X[, y])
Learn and apply the dimension reduction on the train data.
get_params([deep])
Get parameters for this estimator.
inverse_transform(X)
Transform data back to its original space.
predict(X[, copy])
Predict targets of given samples.
score(X, y[, sample_weight])
Return the coefficient of determination \(R^2\) of the prediction.
set_params(**params)
Set the parameters of this estimator.
transform(X[, Y, copy])
Apply the dimension reduction.
Fit model to data.
Training vectors, where n_samples is the number of samples and n_features is the number of predictors.
Target vectors, where n_samples is the number of samples and n_targets is the number of response variables.
Learn and apply the dimension reduction on the train data.
Training vectors, where n_samples is the number of samples and n_features is the number of predictors.
Target vectors, where n_samples is the number of samples and n_targets is the number of response variables.
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.
Transform data back to its original space.
New data, where n_samples is the number of samples and n_components is the number of pls components.
This transformation will only be exact if n_components=n_features.
Predict targets of given samples.
Samples.
Whether to copy X and Y, or perform in-place normalization.
This call requires the estimation of a matrix of shape (n_features, n_targets), which may be an issue in high dimensional space.
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.
Apply the dimension reduction.
Samples to transform.
Target vectors.
Whether to copy X and Y, or perform in-place normalization.


Canonical Correlation Analysis, also known as “Mode B” PLS.
Read more in the User Guide.
Number of components to keep. Should be in [1, min(n_samples,
n_features, n_targets)].
Whether to scale X and Y.
the maximum number of iterations of the power method.
The tolerance used as convergence criteria in the power method: the algorithm stops whenever the squared norm of u_i - u_{i-1} is less than tol, where u corresponds to the left singular vector.
Whether to copy X and Y in fit before applying centering, and potentially scaling. If False, these operations will be done inplace, modifying both arrays.
The left singular vectors of the cross-covariance matrices of each iteration.
The right singular vectors of the cross-covariance matrices of each iteration.
The loadings of X.
The loadings of Y.
The transformed training samples.
Deprecated since version 0.24: x_scores_ is deprecated in 0.24 and will be removed in 1.1 (renaming of 0.26). You can just call transform on the training data instead.
The transformed training targets.
Deprecated since version 0.24: y_scores_ is deprecated in 0.24 and will be removed in 1.1 (renaming of 0.26). You can just call transform on the training data instead.
The projection matrix used to transform X.
The projection matrix used to transform Y.
The coefficients of the linear model such that Y is approximated as Y = X @ coef_.
Number of iterations of the power method, for each component.
See also
fit(X, Y)
Fit model to data.
fit_transform(X[, y])
Learn and apply the dimension reduction on the train data.
get_params([deep])
Get parameters for this estimator.
inverse_transform(X)
Transform data back to its original space.
predict(X[, copy])
Predict targets of given samples.
score(X, y[, sample_weight])
Return the coefficient of determination \(R^2\) of the prediction.
set_params(**params)
Set the parameters of this estimator.
transform(X[, Y, copy])
Apply the dimension reduction.
Fit model to data.
Training vectors, where n_samples is the number of samples and n_features is the number of predictors.
Target vectors, where n_samples is the number of samples and n_targets is the number of response variables.
Learn and apply the dimension reduction on the train data.
Training vectors, where n_samples is the number of samples and n_features is the number of predictors.
Target vectors, where n_samples is the number of samples and n_targets is the number of response variables.
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.
Transform data back to its original space.
New data, where n_samples is the number of samples and n_components is the number of pls components.
This transformation will only be exact if n_components=n_features.
Predict targets of given samples.
Samples.
Whether to copy X and Y, or perform in-place normalization.
This call requires the estimation of a matrix of shape (n_features, n_targets), which may be an issue in high dimensional space.
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.
Apply the dimension reduction.
Samples to transform.
Target vectors.
Whether to copy X and Y, or perform in-place normalization.
Compare cross decomposition methods
Multilabel classification


Fit model to data.
Training vectors, where n_samples is the number of samples and n_features is the number of predictors.
Target vectors, where n_samples is the number of samples and n_targets is the number of response variables.


Learn and apply the dimension reduction on the train data.
Training vectors, where n_samples is the number of samples and n_features is the number of predictors.
Target vectors, where n_samples is the number of samples and n_targets is the number of response variables.


Transform data back to its original space.
New data, where n_samples is the number of samples and n_components is the number of pls components.
This transformation will only be exact if n_components=n_features.


Predict targets of given samples.
Samples.
Whether to copy X and Y, or perform in-place normalization.
This call requires the estimation of a matrix of shape (n_features, n_targets), which may be an issue in high dimensional space.


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.


Apply the dimension reduction.
Samples to transform.
Target vectors.
Whether to copy X and Y, or perform in-place normalization.


Partial Least Squares transformer and regressor.
Read more in the User Guide.
New in version 0.8.
Number of components to keep. Should be in [1, min(n_samples,
n_features, n_targets)].
Whether to scale X and Y.
The algorithm used to estimate the first singular vectors of the cross-covariance matrix. ‘nipals’ uses the power method while ‘svd’ will compute the whole SVD.
the maximum number of iterations of the power method when algorithm='nipals'. Ignored otherwise.
The tolerance used as convergence criteria in the power method: the algorithm stops whenever the squared norm of u_i - u_{i-1} is less than tol, where u corresponds to the left singular vector.
Whether to copy X and Y in fit before applying centering, and potentially scaling. If False, these operations will be done inplace, modifying both arrays.
The left singular vectors of the cross-covariance matrices of each iteration.
The right singular vectors of the cross-covariance matrices of each iteration.
The loadings of X.
The loadings of Y.
The transformed training samples.
Deprecated since version 0.24: x_scores_ is deprecated in 0.24 and will be removed in 1.1 (renaming of 0.26). You can just call transform on the training data instead.
The transformed training targets.
Deprecated since version 0.24: y_scores_ is deprecated in 0.24 and will be removed in 1.1 (renaming of 0.26). You can just call transform on the training data instead.
The projection matrix used to transform X.
The projection matrix used to transform Y.
The coefficients of the linear model such that Y is approximated as Y = X @ coef_.
Number of iterations of the power method, for each component. Empty if algorithm='svd'.
See also
fit(X, Y)
Fit model to data.
fit_transform(X[, y])
Learn and apply the dimension reduction on the train data.
get_params([deep])
Get parameters for this estimator.
inverse_transform(X)
Transform data back to its original space.
predict(X[, copy])
Predict targets of given samples.
score(X, y[, sample_weight])
Return the coefficient of determination \(R^2\) of the prediction.
set_params(**params)
Set the parameters of this estimator.
transform(X[, Y, copy])
Apply the dimension reduction.
Fit model to data.
Training vectors, where n_samples is the number of samples and n_features is the number of predictors.
Target vectors, where n_samples is the number of samples and n_targets is the number of response variables.
Learn and apply the dimension reduction on the train data.
Training vectors, where n_samples is the number of samples and n_features is the number of predictors.
Target vectors, where n_samples is the number of samples and n_targets is the number of response variables.
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.
Transform data back to its original space.
New data, where n_samples is the number of samples and n_components is the number of pls components.
This transformation will only be exact if n_components=n_features.
Predict targets of given samples.
Samples.
Whether to copy X and Y, or perform in-place normalization.
This call requires the estimation of a matrix of shape (n_features, n_targets), which may be an issue in high dimensional space.
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.
Apply the dimension reduction.
Samples to transform.
Target vectors.
Whether to copy X and Y, or perform in-place normalization.


Partial Least Squares transformer and regressor.
Read more in the User Guide.
New in version 0.8.
Number of components to keep. Should be in [1, min(n_samples,
n_features, n_targets)].
Whether to scale X and Y.
The algorithm used to estimate the first singular vectors of the cross-covariance matrix. ‘nipals’ uses the power method while ‘svd’ will compute the whole SVD.
the maximum number of iterations of the power method when algorithm='nipals'. Ignored otherwise.
The tolerance used as convergence criteria in the power method: the algorithm stops whenever the squared norm of u_i - u_{i-1} is less than tol, where u corresponds to the left singular vector.
Whether to copy X and Y in fit before applying centering, and potentially scaling. If False, these operations will be done inplace, modifying both arrays.
The left singular vectors of the cross-covariance matrices of each iteration.
The right singular vectors of the cross-covariance matrices of each iteration.
The loadings of X.
The loadings of Y.
The transformed training samples.
Deprecated since version 0.24: x_scores_ is deprecated in 0.24 and will be removed in 1.1 (renaming of 0.26). You can just call transform on the training data instead.
The transformed training targets.
Deprecated since version 0.24: y_scores_ is deprecated in 0.24 and will be removed in 1.1 (renaming of 0.26). You can just call transform on the training data instead.
The projection matrix used to transform X.
The projection matrix used to transform Y.
The coefficients of the linear model such that Y is approximated as Y = X @ coef_.
Number of iterations of the power method, for each component. Empty if algorithm='svd'.
See also
fit(X, Y)
Fit model to data.
fit_transform(X[, y])
Learn and apply the dimension reduction on the train data.
get_params([deep])
Get parameters for this estimator.
inverse_transform(X)
Transform data back to its original space.
predict(X[, copy])
Predict targets of given samples.
score(X, y[, sample_weight])
Return the coefficient of determination \(R^2\) of the prediction.
set_params(**params)
Set the parameters of this estimator.
transform(X[, Y, copy])
Apply the dimension reduction.
Fit model to data.
Training vectors, where n_samples is the number of samples and n_features is the number of predictors.
Target vectors, where n_samples is the number of samples and n_targets is the number of response variables.
Learn and apply the dimension reduction on the train data.
Training vectors, where n_samples is the number of samples and n_features is the number of predictors.
Target vectors, where n_samples is the number of samples and n_targets is the number of response variables.
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.
Transform data back to its original space.
New data, where n_samples is the number of samples and n_components is the number of pls components.
This transformation will only be exact if n_components=n_features.
Predict targets of given samples.
Samples.
Whether to copy X and Y, or perform in-place normalization.
This call requires the estimation of a matrix of shape (n_features, n_targets), which may be an issue in high dimensional space.
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.
Apply the dimension reduction.
Samples to transform.
Target vectors.
Whether to copy X and Y, or perform in-place normalization.
Compare cross decomposition methods


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.


PLS regression
PLSRegression is also known as PLS2 or PLS1, depending on the number of targets.
Read more in the User Guide.
New in version 0.8.
Number of components to keep. Should be in [1, min(n_samples,
n_features, n_targets)].
Whether to scale X and Y.
The algorithm used to estimate the first singular vectors of the cross-covariance matrix. ‘nipals’ uses the power method while ‘svd’ will compute the whole SVD.
The maximum number of iterations of the power method when algorithm='nipals'. Ignored otherwise.
The tolerance used as convergence criteria in the power method: the algorithm stops whenever the squared norm of u_i - u_{i-1} is less than tol, where u corresponds to the left singular vector.
Whether to copy X and Y in fit before applying centering, and potentially scaling. If False, these operations will be done inplace, modifying both arrays.
The left singular vectors of the cross-covariance matrices of each iteration.
The right singular vectors of the cross-covariance matrices of each iteration.
The loadings of X.
The loadings of Y.
The transformed training samples.
The transformed training targets.
The projection matrix used to transform X.
The projection matrix used to transform Y.
The coefficients of the linear model such that Y is approximated as Y = X @ coef_.
Number of iterations of the power method, for each component. Empty if algorithm='svd'.
fit(X, Y)
Fit model to data.
fit_transform(X[, y])
Learn and apply the dimension reduction on the train data.
get_params([deep])
Get parameters for this estimator.
inverse_transform(X)
Transform data back to its original space.
predict(X[, copy])
Predict targets of given samples.
score(X, y[, sample_weight])
Return the coefficient of determination \(R^2\) of the prediction.
set_params(**params)
Set the parameters of this estimator.
transform(X[, Y, copy])
Apply the dimension reduction.
Fit model to data.
Training vectors, where n_samples is the number of samples and n_features is the number of predictors.
Target vectors, where n_samples is the number of samples and n_targets is the number of response variables.
Learn and apply the dimension reduction on the train data.
Training vectors, where n_samples is the number of samples and n_features is the number of predictors.
Target vectors, where n_samples is the number of samples and n_targets is the number of response variables.
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.
Transform data back to its original space.
New data, where n_samples is the number of samples and n_components is the number of pls components.
This transformation will only be exact if n_components=n_features.
Predict targets of given samples.
Samples.
Whether to copy X and Y, or perform in-place normalization.
This call requires the estimation of a matrix of shape (n_features, n_targets), which may be an issue in high dimensional space.
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.
Apply the dimension reduction.
Samples to transform.
Target vectors.
Whether to copy X and Y, or perform in-place normalization.


PLS regression
PLSRegression is also known as PLS2 or PLS1, depending on the number of targets.
Read more in the User Guide.
New in version 0.8.
Number of components to keep. Should be in [1, min(n_samples,
n_features, n_targets)].
Whether to scale X and Y.
The algorithm used to estimate the first singular vectors of the cross-covariance matrix. ‘nipals’ uses the power method while ‘svd’ will compute the whole SVD.
The maximum number of iterations of the power method when algorithm='nipals'. Ignored otherwise.
The tolerance used as convergence criteria in the power method: the algorithm stops whenever the squared norm of u_i - u_{i-1} is less than tol, where u corresponds to the left singular vector.
Whether to copy X and Y in fit before applying centering, and potentially scaling. If False, these operations will be done inplace, modifying both arrays.
The left singular vectors of the cross-covariance matrices of each iteration.
The right singular vectors of the cross-covariance matrices of each iteration.
The loadings of X.
The loadings of Y.
The transformed training samples.
The transformed training targets.
The projection matrix used to transform X.
The projection matrix used to transform Y.
The coefficients of the linear model such that Y is approximated as Y = X @ coef_.
Number of iterations of the power method, for each component. Empty if algorithm='svd'.
fit(X, Y)
Fit model to data.
fit_transform(X[, y])
Learn and apply the dimension reduction on the train data.
get_params([deep])
Get parameters for this estimator.
inverse_transform(X)
Transform data back to its original space.
predict(X[, copy])
Predict targets of given samples.
score(X, y[, sample_weight])
Return the coefficient of determination \(R^2\) of the prediction.
set_params(**params)
Set the parameters of this estimator.
transform(X[, Y, copy])
Apply the dimension reduction.
Fit model to data.
Training vectors, where n_samples is the number of samples and n_features is the number of predictors.
Target vectors, where n_samples is the number of samples and n_targets is the number of response variables.
Learn and apply the dimension reduction on the train data.
Training vectors, where n_samples is the number of samples and n_features is the number of predictors.
Target vectors, where n_samples is the number of samples and n_targets is the number of response variables.
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.
Transform data back to its original space.
New data, where n_samples is the number of samples and n_components is the number of pls components.
This transformation will only be exact if n_components=n_features.
Predict targets of given samples.
Samples.
Whether to copy X and Y, or perform in-place normalization.
This call requires the estimation of a matrix of shape (n_features, n_targets), which may be an issue in high dimensional space.
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.
Apply the dimension reduction.
Samples to transform.
Target vectors.
Whether to copy X and Y, or perform in-place normalization.
Principal Component Regression vs Partial Least Squares Regression
Compare cross decomposition methods


Partial Least Square SVD.
This transformer simply performs a SVD on the crosscovariance matrix X’Y. It is able to project both the training data X and the targets Y. The training data X is projected on the left singular vectors, while the targets are projected on the right singular vectors.
Read more in the User Guide.
New in version 0.8.
The number of components to keep. Should be in [1,
min(n_samples, n_features, n_targets)].
Whether to scale X and Y.
Whether to copy X and Y in fit before applying centering, and potentially scaling. If False, these operations will be done inplace, modifying both arrays.
The left singular vectors of the SVD of the cross-covariance matrix. Used to project X in transform.
The right singular vectors of the SVD of the cross-covariance matrix. Used to project X in transform.
The transformed training samples.
Deprecated since version 0.24: x_scores_ is deprecated in 0.24 and will be removed in 1.1 (renaming of 0.26). You can just call transform on the training data instead.
The transformed training targets.
Deprecated since version 0.24: y_scores_ is deprecated in 0.24 and will be removed in 1.1 (renaming of 0.26). You can just call transform on the training data instead.
See also
fit(X, Y)
Fit model to data.
fit_transform(X[, y])
Learn and apply the dimensionality reduction.
get_params([deep])
Get parameters for this estimator.
set_params(**params)
Set the parameters of this estimator.
transform(X[, Y])
Apply the dimensionality reduction.
Fit model to data.
Training samples.
Targets.
Learn and apply the dimensionality reduction.
Training samples.
Targets.
The transformed data X_tranformed if Y is not None, (X_transformed, Y_transformed) otherwise.
Get parameters for this estimator.
If True, will return the parameters for this estimator and contained subobjects that are estimators.
Parameter names mapped to their values.
Set the parameters of this estimator.
The method works on simple estimators as well as on nested objects (such as Pipeline). The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.
Estimator parameters.
Estimator instance.
Apply the dimensionality reduction.
Samples to be transformed.
Targets.
The transformed data X_tranformed if Y is not None, (X_transformed, Y_transformed) otherwise.


Fit model to data.
Training samples.
Targets.


Learn and apply the dimensionality reduction.
Training samples.
Targets.
The transformed data X_tranformed if Y is not None, (X_transformed, Y_transformed) otherwise.


Apply the dimensionality reduction.
Samples to be transformed.
Targets.
The transformed data X_tranformed if Y is not None, (X_transformed, Y_transformed) otherwise.


Delete all the content of the data home cache.
The path to scikit-learn data directory. If None, the default path is ~/sklearn_learn_data.


Dump the dataset in svmlight / libsvm file format.
This format is a text-based format, with one sample per line. It does not store zero valued features hence is suitable for sparse dataset.
The first element of each line can be used to store a target variable to predict.
Training vectors, where n_samples is the number of samples and n_features is the number of features.
Target values. Class labels must be an integer or float, or array-like objects of integer or float for multilabel classifications.
If string, specifies the path that will contain the data. If file-like, data will be written to f. f should be opened in binary mode.
Whether column indices should be written zero-based (True) or one-based (False).
Comment to insert at the top of the file. This should be either a Unicode string, which will be encoded as UTF-8, or an ASCII byte string. If a comment is given, then it will be preceded by one that identifies the file as having been dumped by scikit-learn. Note that not all tools grok comments in SVMlight files.
Array containing pairwise preference constraints (qid in svmlight format).
Samples may have several labels each (see https://www.csie.ntu.edu.tw/~cjlin/libsvmtools/datasets/multilabel.html)
New in version 0.17: parameter multilabel to support multilabel datasets.