#NEWLINE# def _cov( X , shrinkage = None ) : #NEWLINE# #INDENT# "Estimate covariance matrix (using optional shrinkage).\n\n    Parameters\n    ----------\n    X : array-like, shape (n_samples, n_features)\n        Input data.\n\n    shrinkage : string or float, optional\n        Shrinkage parameter, possible values:\n          - None or 'empirical': no shrinkage (default).\n          - 'auto': automatic shrinkage using the Ledoit-Wolf lemma.\n          - float between 0 and 1: fixed shrinkage parameter.\n\n    Returns\n    -------\n    s : array, shape (n_features, n_features)\n        Estimated covariance matrix.\n    " #NEWLINE# shrinkage = ( 'empirical' if ( shrinkage is None ) else shrinkage ) #NEWLINE# if isinstance ( shrinkage , string_types ) : #NEWLINE# #INDENT# if ( shrinkage == 'auto' ) : #NEWLINE# #INDENT# sc = StandardScaler ( ) #NEWLINE# X = sc . fit_transform ( X ) #NEWLINE# s = ledoit_wolf ( X ) [ 0 ] #NEWLINE# s = ( ( X . scale_ [ : , np . newaxis ] * s ) * sc . scale_ [ np . newaxis , : ] ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( shrinkage == 'empirical' ) : #NEWLINE# #INDENT# s = empirical_covariance ( X ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# raise ValueError ( 'unknown shrinkage parameter' ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( isinstance ( shrinkage , float ) or isinstance ( shrinkage , int ) ) : #NEWLINE# #INDENT# if ( ( shrinkage < 0 ) or ( shrinkage > 1 ) ) : #NEWLINE# #INDENT# raise ValueError ( 'shrinkage parameter must be between 0 and 1' ) #NEWLINE# #UNINDENT# s = shrunk_covariance ( empirical_covariance ( X ) , shrinkage ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# raise TypeError ( 'shrinkage must be of string or int type' ) #NEWLINE# #UNINDENT# #UNINDENT# return s