graphical_lasso
- sklearn.covariance.graphical_lasso(emp_cov, alpha, *, mode='cd', tol=0.0001, enet_tol=0.0001, max_iter=100, verbose=False, return_costs, ,
L1-penalized covariance estimator.
Read more in the User Guide.
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 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.
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.
>>> import numpy as np
>>> from sklearn.datasets import make_sparse_spd_matrix
>>> from sklearn.covariance import empirical_covariance, graphical_lasso
>>> true_cov = make_sparse_spd_matrix(n_dim=3,random_state=42)
>>>