def shrunk_covariance(emp_cov, shrinkage=0.1):
 emp_cov = check_array(emp_cov)
 n_features = emp_cov.shape[0]
 mu = (np.trace(emp_cov) / n_features)
 shrunk_cov = ((1.0 - shrinkage) * emp_cov)
 shrunk_cov.flat[::(n_features + 1)] += (shrinkage * mu)
 return shrunk_cov

def shrunk_covariance ( emp_cov , shrinkage = 0.1 ) : emp_cov = check_array ( emp_cov ) n_features = emp_cov . shape [ 0 ] mu = ( np . trace ( emp_cov ) / n_features ) shrunk_cov = ( ( 1.0 - shrinkage ) * emp_cov ) shrunk_cov . flat [ : : ( n_features + 1 ) ] += ( shrinkage * mu ) return shrunk_cov
calculates a covariance matrix shrunk on the diagonal read more in the :ref:user guide <shrunk_covariance> .