parameters: (X, assume_centered=False)
return_statement: return shrunk_cov, shrinkage
docstring: Estimate covariance with the Oracle Approximating Shrinkage algorithm.
  
      Parameters
      ----------
      X : array-like, shape (n_samples, n_features)
          Data from which to compute the covariance estimate.
  
      assume_centered : boolean
        If True, data will not be centered before computation.
        Useful to work with data whose mean is significantly equal to
        zero but is not exactly zero.
        If False, data will be centered before computation.
  
      Returns
      -------
      shrunk_cov : array-like, shape (n_features, n_features)
          Shrunk covariance.
  
      shrinkage : float
          Coefficient in the convex combination used for the computation
          of the shrunk estimate.
  
      Notes
      -----
      The regularised (shrunk) covariance is:
  
      (1 - shrinkage) * cov + shrinkage * mu * np.identity(n_features)
  
      where mu = trace(cov) / n_features
  
      The formula we used to implement the OAS is slightly modified compared
      to the one given in the article. See :class:`OAS` for more details.
docstring_summary: Estimate covariance with the Oracle Approximating Shrinkage algorithm.
docstring_tokens: Estimate covariance with the Oracle Approximating Shrinkage algorithm .
function: def oas(X, assume_centered=False):
      """Estimate covariance with the Oracle Approximating Shrinkage algorithm.
  
      Parameters
      ----------
      X : array-like, shape (n_samples, n_features)
          Data from which to compute the covariance estimate.
  
      assume_centered : boolean
        If True, data will not be centered before computation.
        Useful to work with data whose mean is significantly equal to
        zero but is not exactly zero.
        If False, data will be centered before computation.
  
      Returns
      -------
      shrunk_cov : array-like, shape (n_features, n_features)
          Shrunk covariance.
  
      shrinkage : float
          Coefficient in the convex combination used for the computation
          of the shrunk estimate.
  
      Notes
      -----
      The regularised (shrunk) covariance is:
  
      (1 - shrinkage) * cov + shrinkage * mu * np.identity(n_features)
  
      where mu = trace(cov) / n_features
  
      The formula we used to implement the OAS is slightly modified compared
      to the one given in the article. See :class:`OAS` for more details.
  
      """
      X = np.asarray(X)
      # for only one feature, the result is the same whatever the shrinkage
      if len(X.shape) == 2 and X.shape[1] == 1:
          if not assume_centered:
              X = X - X.mean()
          return np.atleast_2d((X ** 2).mean()), 0.
      if X.ndim == 1:
          X = np.reshape(X, (1, -1))
          warnings.warn("Only one sample available. "
                        "You may want to reshape your data array")
          n_samples = 1
          n_features = X.size
      else:
          n_samples, n_features = X.shape
  
      emp_cov = empirical_covariance(X, assume_centered=assume_centered)
      mu = np.trace(emp_cov) / n_features
  
      # formula from Chen et al.'s **implementation**
      alpha = np.mean(emp_cov ** 2)
      num = alpha + mu ** 2
      den = (n_samples + 1.) * (alpha - (mu ** 2) / n_features)
  
      shrinkage = 1. if den == 0 else min(num / den, 1.)
      shrunk_cov = (1. - shrinkage) * emp_cov
      shrunk_cov.flat[::n_features + 1] += shrinkage * mu
  
      return shrunk_cov, shrinkage
function_tokens: def oas ( X , assume_centered = False ) : X = np . asarray ( X ) # for only one feature, the result is the same whatever the shrinkage if len ( X . shape ) == 2 and X . shape [ 1 ] == 1 : if not assume_centered : X = X - X . mean ( ) return np . atleast_2d ( ( X ** 2 ) . mean ( ) ) , 0. if X . ndim == 1 : X = np . reshape ( X , ( 1 , - 1 ) ) warnings . warn ( "Only one sample available. " "You may want to reshape your data array" ) n_samples = 1 n_features = X . size else : n_samples , n_features = X . shape emp_cov = empirical_covariance ( X , assume_centered = assume_centered ) mu = np . trace ( emp_cov ) / n_features # formula from Chen et al.'s **implementation** alpha = np . mean ( emp_cov ** 2 ) num = alpha + mu ** 2 den = ( n_samples + 1. ) * ( alpha - ( mu ** 2 ) / n_features ) shrinkage = 1. if den == 0 else min ( num / den , 1. ) shrunk_cov = ( 1. - shrinkage ) * emp_cov shrunk_cov . flat [ : : n_features + 1 ] += shrinkage * mu return shrunk_cov , shrinkage