Sparse inverse covariance estimation with an l1-penalized estimator.
Read more in the :ref:`User Guide <sparse_inverse_covariance>`.
.. versionchanged:: v0.20 GraphLasso has been renamed to GraphicalLasso
Parameters ---------- alpha : float, default=0.01 The regularization parameter: the higher alpha, the more regularization, the sparser the inverse covariance. Range is (0, inf].
mode : 'cd', 'lars'
, default='cd' 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.
tol : float, default=1e-4 The tolerance to declare convergence: if the dual gap goes below this value, iterations are stopped. Range is (0, inf].
enet_tol : float, default=1e-4 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].
max_iter : int, default=100 The maximum number of iterations.
verbose : bool, default=False If verbose is True, the objective function and dual gap are plotted at each iteration.
assume_centered : bool, default=False 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.
Attributes ---------- location_ : ndarray of shape (n_features,) Estimated location, i.e. the estimated mean.
covariance_ : ndarray of shape (n_features, n_features) Estimated covariance matrix
precision_ : ndarray of shape (n_features, n_features) Estimated pseudo inverse matrix.
n_iter_ : int Number of iterations run.
Examples -------- >>> import numpy as np >>> from sklearn.covariance import GraphicalLasso >>> 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 = GraphicalLasso().fit(X) >>> np.around(cov.covariance_, decimals=3) array([0.816, 0.049, 0.218, 0.019],
[0.049, 0.364, 0.017, 0.034],
[0.218, 0.017, 0.322, 0.093],
[0.019, 0.034, 0.093, 0.69 ]
) >>> np.around(cov.location_, decimals=3) array(0.073, 0.04 , 0.038, 0.143
)
See Also -------- graphical_lasso, GraphicalLassoCV