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. - shrinkage) * emp_cov
    shrunk_cov.flat[::n_features + 1] += shrinkage * mu

    return shrunk_cov
Calculates a covariance matrix shrunk on the diagonal
dataset/ETHPy150Open scikit-learn/scikit-learn/sklearn/covariance/shrunk_covariance_.py/shrunk_covariance