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 [1, inf) for an integer. Range is (0, inf] for an array-like of floats.
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:
None, to use the default 5-fold cross-validation,
integer, to specify the number of folds.
An iterable yielding (train, test) splits as arrays of indices.
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.
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
.
Added in version 1.3.
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).
The list of values of the objective function and the dual gap at each iteration. Returned only if return_costs is True.
Added in version 1.3.
Penalization parameter selected.
A dict with keys:
All penalization parameters explored.
Log-likelihood score on left-out data across (k)th fold.
Added in version 1.0.
Mean of scores over the folds.
Added in version 1.0.
Standard deviation of scores over the folds.
Added in version 1.0.
Number of iterations run for the optimal alpha.
Number of features seen during fit.
Added in version 0.24.
n_features_in_
,)
Names of features seen during fit. Defined only when X
has feature names that are all strings.
Added in version 1.0.
Notes
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.
In fit
, once the best parameter alpha
is found through cross-validation, the model is fit again using the entire training set.
Examples
>>> import numpy as np >>> from sklearn.covariance import GraphicalLassoCV >>> true_cov = np.array([[0.8, 0.0, 0.2, 0.0], ... [0.0, 0.4, 0.0, 0.0], ... [0.2, 0.0, 0.3, 0.1], ... [0.0, 0.0, 0.1, 0.7]]) >>> np.random.seed(0) >>> X = np.random.multivariate_normal(mean=[0, 0, 0, 0], ... cov=true_cov, ... size=200) >>> cov = GraphicalLassoCV().fit(X) >>> np.around(cov.covariance_, decimals=3) array([[0.816, 0.051, 0.22 , 0.017], [0.051, 0.364, 0.018, 0.036], [0.22 , 0.018, 0.322, 0.094], [0.017, 0.036, 0.094, 0.69 ]]) >>> np.around(cov.location_, decimals=3) array([0.073, 0.04 , 0.038, 0.143])
For an example comparing sklearn.covariance.GraphicalLassoCV
, sklearn.covariance.ledoit_wolf
shrinkage and the empirical covariance on high-dimensional gaussian data, see Sparse inverse covariance estimation.
Compute the Mean Squared Error between two covariance estimators.
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 GraphicalLasso covariance model to X.
Data from which to compute the covariance estimate.
Not used, present for API consistency by convention.
Parameters to be passed to the CV splitter and the cross_val_score function.
Added in version 1.5: Only available if enable_metadata_routing=True
, which can be set by using sklearn.set_config(enable_metadata_routing=True)
. See Metadata Routing User Guide for more details.
Returns the instance itself.
Get metadata routing of this object.
Please check User Guide on how the routing mechanism works.
Added in version 1.5.
A MetadataRouter
encapsulating routing information.
Get parameters for this estimator.
If True, will return the parameters for this estimator and contained subobjects that are estimators.
Parameter names mapped to their values.
Getter for the precision matrix.
The precision matrix associated to the current covariance object.
Compute the squared Mahalanobis distances of given observations.
For a detailed example of how outliers affects the Mahalanobis distance, see Robust covariance estimation and Mahalanobis distances relevance.
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.
Compute the log-likelihood of X_test
under the estimated Gaussian model.
The Gaussian model is defined by its mean and covariance matrix which are represented respectively by self.location_
and self.covariance_
.
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 log-likelihood of X_test
with self.location_
and self.covariance_
as estimators of the Gaussian model mean and covariance matrix respectively.
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.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4