<a id="skfolio-utils-stats-cs-pearson-correlation"></a>

# skfolio.utils.stats.cs_pearson_correlation

<a id="skfolio.utils.stats.cs_pearson_correlation"></a>

### skfolio.utils.stats.cs_pearson_correlation(a, b, weights=None, axis=0, min_count=3, eps=1e-12)

Weighted cross-sectional Pearson correlation.

Computes the weighted Pearson correlation between *a* and *b* along `axis`.
All other dimensions are treated as independent batch dimensions over which the
computation is vectorized.

For vectors $a$ and $b$ with weights $w$:

$$
\rho = \frac{
    \sum_n w_n \,(a_n - \bar a)\,(b_n - \bar b)
}{
    \sqrt{\sum_n w_n \,(a_n - \bar a)^2}\;
    \sqrt{\sum_n w_n \,(b_n - \bar b)^2}
}
$$

where $\bar a = \sum_n w_n a_n / \sum_n w_n$ (and likewise for $\bar b$).

* **Parameters:**
  **a** *ndarray*
  : First array.

  **b** *ndarray*
  : Second array, broadcastable to the same shape as *a*.

  **weights** *ndarray, optional*
  : Non-negative weights, broadcastable to *a* along `axis`.
    `None` uses equal weights. Non-finite and zero weights are excluded
    from weighted correlations.

  **axis** *int, default=0*
  : The cross-sectional axis along which correlation is computed.

  **min_count** *int, default=3*
  : Minimum number of effective observations along `axis`. Without
    `weights`, this is the number of jointly finite observations. With
    `weights`, this is the number of jointly finite observations with
    finite strictly positive weight.

  **eps** *float, default=1e-12*
  : Denominator threshold below which `NaN` is returned to guard against
    near-constant vectors.
* **Returns:**
  **corr** *float or ndarray*
  : Scalar when inputs are 1D, otherwise an array with `axis`
    removed.

