Module Expr Str Print NameLoad Import alias identifier Import alias identifier ImportFrom alias alias ImportFrom alias alias Expr Call AttributeLoad AttributeLoad NameLoad attr attr Num Assign NameStore Num Assign NameStore Num Assign NameStore Call NameLoad BinOpPow NameLoad Call AttributeLoad NameLoad attr NameLoad Assign NameStore Call NameLoad NameLoad Assign NameStore Call AttributeLoad NameLoad attr Num Num Num Assign NameStore Num Assign NameStore Call AttributeLoad NameLoad attr TupleLoad AttributeLoad NameLoad attr NameLoad Assign NameStore Call AttributeLoad NameLoad attr TupleLoad AttributeLoad NameLoad attr NameLoad Assign NameStore Call AttributeLoad NameLoad attr TupleLoad AttributeLoad NameLoad attr NameLoad Assign NameStore Call AttributeLoad NameLoad attr TupleLoad AttributeLoad NameLoad attr NameLoad For TupleStore NameStore NameStore Call NameLoad NameLoad body For NameStore Call NameLoad NameLoad body Assign NameStore Call AttributeLoad NameLoad attr Call AttributeLoad AttributeLoad NameLoad attr attr keyword TupleLoad NameLoad NameLoad AttributeLoad NameLoad attr Assign NameStore Call NameLoad keyword NameLoad keyword NameLoad Expr Call AttributeLoad NameLoad attr NameLoad Assign SubscriptStore NameLoad Index TupleLoad NameLoad NameLoad Call AttributeLoad NameLoad attr NameLoad keyword NameLoad Assign SubscriptStore NameLoad Index TupleLoad NameLoad NameLoad AttributeLoad NameLoad attr Assign NameStore Call NameLoad keyword NameLoad keyword NameLoad Expr Call AttributeLoad NameLoad attr NameLoad Assign SubscriptStore NameLoad Index TupleLoad NameLoad NameLoad Call AttributeLoad NameLoad attr NameLoad keyword NameLoad Assign SubscriptStore NameLoad Index TupleLoad NameLoad NameLoad AttributeLoad NameLoad attr Expr Call AttributeLoad NameLoad attr Num Num Num Expr Call AttributeLoad NameLoad attr NameLoad Call AttributeLoad NameLoad attr Num keyword Call AttributeLoad NameLoad attr Num keyword Str keyword Str keyword Num Expr Call AttributeLoad NameLoad attr NameLoad Call AttributeLoad NameLoad attr Num keyword Call AttributeLoad NameLoad attr Num keyword Str keyword Str keyword Num Expr Call AttributeLoad NameLoad attr Str Expr Call AttributeLoad NameLoad attr keyword Str Expr Call AttributeLoad NameLoad attr Str Expr Call AttributeLoad NameLoad attr Num Num Expr Call AttributeLoad NameLoad attr Num Num Num Expr Call AttributeLoad NameLoad attr NameLoad Call AttributeLoad NameLoad attr Num keyword Call AttributeLoad NameLoad attr Num keyword Str keyword Str keyword Num Expr Call AttributeLoad NameLoad attr NameLoad Call AttributeLoad NameLoad attr Num keyword Call AttributeLoad NameLoad attr Num keyword Str keyword Str keyword Num Expr Call AttributeLoad NameLoad attr Str Expr Call AttributeLoad NameLoad attr Str Expr Call AttributeLoad NameLoad attr keyword Str Expr Call AttributeLoad NameLoad attr SubscriptLoad Call AttributeLoad NameLoad attr Index Num BinOpAdd Num BinOpDiv BinOpSub SubscriptLoad Call AttributeLoad NameLoad attr Index Num SubscriptLoad Call AttributeLoad NameLoad attr Index Num Num Expr Call AttributeLoad NameLoad attr Num Num Expr Call AttributeLoad NameLoad attr
N/A N/A 
=============================
Ledoit-Wolf vs OAS estimation
=============================

The usual covariance maximum likelihood estimate can be regularized
using shrinkage. Ledoit and Wolf proposed a close formula to compute
the asymptotically optimal shrinkage parameter (minimizing a MSE
criterion), yielding the Ledoit-Wolf covariance estimate.

Chen et al. proposed an improvement of the Ledoit-Wolf shrinkage
parameter, the OAS coefficient, whose convergence is significantly
better under the assumption that the data are Gaussian.

This example, inspired from Chen's publication [1], shows a comparison
of the estimated MSE of the LW and OAS methods, using Gaussian
distributed data.

[1] "Shrinkage Algorithms for MMSE Covariance Estimation"
Chen et al., IEEE Trans. on Sign. Proc., Volume 58, Issue 10, October 2010.

 N/A __doc__ N/A numpy np N/A matplotlib.pyplot plt scipy.linalg toeplitz cholesky sklearn.covariance LedoitWolf OAS N/A N/A N/A N/A np random seed 0 N/A n_features 100 N/A r 0.1 N/A real_cov N/A toeplitz N/A r N/A N/A np arange n_features N/A coloring_matrix N/A cholesky real_cov N/A n_samples_range N/A N/A np arange 6 31 1 N/A repeat 100 N/A lw_mse N/A N/A np zeros N/A N/A n_samples_range size repeat N/A oa_mse N/A N/A np zeros N/A N/A n_samples_range size repeat N/A lw_shrinkage N/A N/A np zeros N/A N/A n_samples_range size repeat N/A oa_shrinkage N/A N/A np zeros N/A N/A n_samples_range size repeat N/A N/A i n_samples N/A enumerate n_samples_range N/A N/A j N/A range repeat N/A N/A X N/A N/A np dot N/A N/A N/A np random normal size N/A n_samples n_features N/A coloring_matrix T N/A lw N/A LedoitWolf store_precision False assume_centered True N/A N/A N/A lw fit X N/A N/A lw_mse N/A N/A i j N/A N/A lw error_norm real_cov scaling False N/A N/A lw_shrinkage N/A N/A i j N/A lw shrinkage_ N/A oa N/A OAS store_precision False assume_centered True N/A N/A N/A oa fit X N/A N/A oa_mse N/A N/A i j N/A N/A oa error_norm real_cov scaling False N/A N/A oa_shrinkage N/A N/A i j N/A oa shrinkage_ N/A N/A N/A plt subplot 2 1 1 N/A N/A N/A plt errorbar n_samples_range N/A N/A lw_mse mean 1 yerr N/A N/A lw_mse std 1 label Ledoit-Wolf color navy lw 2 N/A N/A N/A plt errorbar n_samples_range N/A N/A oa_mse mean 1 yerr N/A N/A oa_mse std 1 label OAS color darkorange lw 2 N/A N/A N/A plt ylabel Squared error N/A N/A N/A plt legend loc upper right N/A N/A N/A plt title Comparison of covariance estimators N/A N/A N/A plt xlim 5 31 N/A N/A N/A plt subplot 2 1 2 N/A N/A N/A plt errorbar n_samples_range N/A N/A lw_shrinkage mean 1 yerr N/A N/A lw_shrinkage std 1 label Ledoit-Wolf color navy lw 2 N/A N/A N/A plt errorbar n_samples_range N/A N/A oa_shrinkage mean 1 yerr N/A N/A oa_shrinkage std 1 label OAS color darkorange lw 2 N/A N/A N/A plt xlabel n_samples N/A N/A N/A plt ylabel Shrinkage N/A N/A N/A plt legend loc lower right N/A N/A N/A plt ylim N/A N/A N/A plt ylim N/A 0 N/A 1.0 N/A N/A N/A N/A N/A plt ylim N/A 1 N/A N/A N/A plt ylim N/A 0 10.0 N/A N/A N/A plt xlim 5 31 N/A N/A N/A plt show