gcor : A Python Implementation of Categorical Gini Correlation and Its Inference
Sameera Hewage · 2025
Read gcor : A Python Implementation of Categorical Gini Correlation and Its Inference by Sameera Hewage (2025) in the Tower of Babel, a free online library of public-domain works preserved in clean, searchable text. No sign-up. The full text is served as a plain-text file at a predictable URL, where text is present: https://antarctic-labs.com/tower-of-babel/arxiv-2506-19230.txt.
Introduction
Sameera Hewage presents a software tool in a 2025 paper for measuring how a number and a category move together. The measure, called Categorical Gini Correlation, has a rare plus: a score of zero goes hand in hand with the two traits being fully unrelated. It has also beaten older measures at picking useful traits for sorting tasks.
The tool, named gcor, is written in Python and computes the measure quickly. It also builds ranges that likely hold the true value and runs tests for whether any link exists at all. Speed comes from vector math and from splitting work across cores. The paper shows stats users how to run each step and read the output.
Catalog record
| CREATOR | Sameera Hewage |
|---|---|
| YEAR | 2025 |
| COLLECTION | PAPERS |
| FORMAT | TXT |
| FILE SIZE | 17 KB |
| VERSION | 1.0 |
| LICENSE | http://creativecommons.org/licenses/by/4.0/ |
| RIGHTS | CC BY |
| SOURCE | arXiv |
Source: https://arxiv.org/abs/2506-19230
Browse the full library · About the Tower of Babel
Full text
The opening of the work, from the library's hosted text:
gcor : A Python Implementation of Categorical Gini Correlation and Its Inference Sameera Hewage Abstract Categorical Gini Correlation (CGC), introduced by Dang et al. [ 1 ] , is a novel dependence measure designed to quantify the association between a numerical variable and a categorical variable. It has appealing properties compared to existing dependence measures, such as zero correlation mutually implying independence between the variables. It has also shown superior performance over existing methods when applied to feature screening for classification. This article presents a Python implementation for computing CGC, constructing confidence intervals, and performing independence tests based on it. Efficient algorithms have been implemented for all procedures, and they have been optimized using vectorization and parallelization to enhance computational efficiency. Keywords: Categorical Gini correlation, Gini distance correlation, dependence measure, statistical inference, Python implementation MSC 2020 subject classification : 62H20, 62G20, 62-07, 62R07 1 Introduction Categorical Gini correlation (CGC), also known as Gini distance correlation , was proposed by Dang et al. [ 1 ] to measure the dependence between a continuous random vector and a categorical variable. CGC has been shown to possess several desirable properties compared to many existing dependence measures. Inference procedures for CGC have been developed in both fixed-dimensional [ 1 , 4 , 9 ] and high-dimensional [ 8 ] settings. Moreover, CGC has been employed as a dependence measure in recent feature selection methods for classification, including those proposed in [ 19 , 8 , 9 , 10 ] . Let X be a continuous random vector following the distribution F in \mathbb{R}^{d} . Let Y be a categorical response variable with possible values L_{1},\dots,L_{K} and a distribution P_{Y} such that P(Y=L_{k})=p_{k}>0 for k=1,2,\dots,K . Assume that the conditional distribution of X given Y=L_{k} is F_{k} . Then Gini covariance and correlation are defined in [ 1 ] as \text{gCov}(\mbox{\boldmath{$X$}},Y)=\Delta-\sum_{k=1}^{K}p_{k}\Delta_{k}, and \displaystyle\rho_{g}(\mbox{\boldmath{$X$}},Y)=\frac{\Delta-\sum_{k=1}^{K}p_{k}\Delta_{k}}{\Delta}, (1) where \displaystyle\Delta=\mathbb{E}\|\mbox{\boldmath{$X$}}_{1}-\mbox{\boldmath{$X$}}_{2}\|,\quad\Delta_{k}=\mathbb{E}\|\mbox{\boldmath{$X$}}_{1}^{(k)}-\mbox{\boldmath{$X$}}_{2}^{(k)}\| are the multivariate Gini mean differences [ 18 , 6 , 5 ] for F and F_{k} respectively with (\mbox{\boldmath{$X$}}_{1},\mbox{\boldmath{$X$}}_{2})^{T} and (\mbox{\boldmath{$X$}}_{1}^{(k)},\mbox{\boldmath{$X$}}_{2}^{(k)})^{T} representing independent pair variables each drawn independently from F and F_{k} , respectively. Thus, it is observed that the Gini correlation can be interpreted as the ratio of between variation and overall variation analogous to Pearson R^{2} in ANOVA model [ 1 ] . The categorical Gini covariance measures dependence by assessing the weighted distance between the marginal and conditional distributions. Let \psi_{k} and \psi be the charactersitic functions of F_{k} and F , respectively. In fact, the Gini covariance in ( 1 ) can be defined by \mbox{gCov}(\mbox{\boldmath{$X$}},Y)=c(d)\sum_{k=1}^{K}p_{k}\int_{\mathbb{R}^{d}}\frac{|\psi_{k}(\mbox{\boldmath{$t$}})-\psi(\mbox{\boldmath{$t$}})|^{2}}{\|\mbox{\boldmath{$t$}}\|^{d+1}}d\mbox{\boldmath{$t$}}, (2) where c(d)=\Gamma((d+1)/2)/\pi^{(d+1)/2} . We observe that \text{gCov}(\mbox{\boldmath{$X$}},Y)\geq 0 , and \text{gCov}(\mbox{\boldmath{$X$}},Y)=0 if and only if X and Y are independent [ 1 ] . The associated Gini correlation standardizes this covariance to ensure it falls within the interval [0,1] . The distance correlation introduced by Székely, Rizzo, and Bakirov [ 14 , 15 , 16 , 7 ] is a widely used dependence measure capable of assessing the association between a continuous random vector and a categorical variable. In contrast, CGC has been shown to offer several advantages: (a) improved computational efficiency, (b) simplified statistical inference, and (c) greater robustness when handling unbalanced data. These appealing properties motivate the development of a Python implementation of CGC and its associated inference procedures, particularly given Python’s growing popularity for data analysis and statistical computing. Nguyen and Dang have implemented CGC and its inference procedures in the R package GiniDistance [ 2 ] . However, to the best of our knowledge, no Python implementation currently exists. The remainder of the paper is organized as follows. In Section 2 , we review some results on CGC, introduce three Python functions, and illustrate each with a real data example. Section 3 presents the impact of the proposed implementation and its applications. In Section 4 , we provide concluding remarks and discuss future work. 2 Functionalities of the package In this section, we first review key results on CGC and its related inference methods, and finally illustrate the Python implementation using a real dataset. 2.1 Estimation of CGC Consider a sample \mathcal{D}=\{(\mbox{\boldmath{$X$}}_{1},Y_{1}),(\mbox{\boldmath{$X$}}_{2},Y_{2}),\dots,(\mbox{\boldmath{$X$}}_{n},Y_{n})\} drawn from the joint distribution of X and Y . We can decompose \mathcal{D} as \mathcal{D}=\mathcal{D}_{1}\cup\mathcal{D}_{2}\cup\dots\cup\mathcal{D}_{K}, where \mathcal{D}_{k}=\{\mbox{\boldmath{$X$}}_{1}^{(k)},\mbox{\boldmath{$X$}}_{2}^{(k)},\dots,\mbox{\boldmath{$X$}}_{n_{k}}^{(k)}\} denotes the sample with Y_{i}=L_{k} , and n_{k} is the number of samples in the k^{\text{th}} class. Categorical Gini correlation can then be estimated unbiasedly as a function of U -statistics [ 1 ] : \hat{\rho}_{g}(\mbox{\boldmath{$X$}},Y)=\frac{\tilde{U}-\sum_{k=1}^{K}\hat{p}_{k}\tilde{U}_{k}}{\tilde{U}}, where \hat{p}_{k}=\frac{n_{k}}{n} , and \displaystyle\tilde{U}_{k} \displaystyle={n\choose 2}_{k}^{-1}\sum_{1\leq i,j\leq n_{k}}\|\mbox{\boldmath{$X$}}_{i}^{(k)}-\mathbf{X}_{j}^{(k)}\|, \displaystyle\tilde{U} \displaystyle={n\choose 2}^{-1}\sum_{1\leq i,j\leq n}\|\mbox{\boldmath{$X$}}_{i}-\mathbf{X}_{j}\|. In this work, the Python function gcor is introduced to calculate the CGC based on the above estimation. 2.2 Confidence Interval Dang et al. [ 1 ] established that when \mathrm{gCor}(\mbox{\boldmath{$X$}},Y)\neq 0 , the estimator \hat{\rho}_{g}(\mbox{\boldmath{$X$}},Y) satisfies the following asymptotic normality: \sqrt{n}\left(\hat{\rho}_{g}(\mbox{\boldmath{$X$}},Y)-\rho_{g}(\mbox{\boldmath{$X$}},Y)\right)\xrightarrow{d}\mathcal{N}(0,\sigma_{g}^{2}), where \sigma_{g}^{2} is the asymptotic variance given by [ 1 ] . Confidence intervals for CGC can be constructed based on this asymptotic normality. However, the variance \sigma_{g}^{2} is often difficult to compute directly due to its complex form. To address this, one can estimate \sigma_{g}^{2} by employing the jackknife method. Let \hat{\rho_{g}}_{(-i)} be the jackknife pseudo value of the Gini correlation estimator \hat{\rho_{g}} based on the sample with the i^{th} observation deleted. Then, the jackknife estimator of \sigma^{2}_{g} is \displaystyle\widehat{\sigma}_{g}^{2}=\dfrac{n-1}{n}\sum_{i=1}^{n}(\hat{\rho}_{g(-i)}-\bar{\hat{\rho}}_{g(\cdot)})^{2}, (3) where \bar{\hat{\rho}}_{g(\cdot)}=\dfrac{1}{n}\sum_{i=1}^{n}{\hat{\rho}}_{g(-i)}, see [ 11 ] . An approximate (1-\alpha)\times 100\% confidence interval for the categorical Gini Correlation can then be constructed as \left[\hat{\rho}_{g}(\mbox{\boldmath{$X$}},Y)-z_{\alpha/2}\frac{\hat{\sigma}_{g}}{\sqrt{n}},\quad\hat{\rho}_{g}(\mbox{\boldmath{$X$}},Y)+z_{\alpha/2}\frac{\hat{\sigma}_{g}}{\sqrt{n}}\right], where z_{\alpha/2} is the upper \alpha/2 quantile of the standard normal distribution. The Python function gcorCI is introduced to calculate the confidence interval in the present work. 2.3 Independence Test The independence test based on CGC is stated as \displaystyle H_{0}:\rho_{g}(\mathcal{\mbox{\boldmath{$X$}}},Y)=0\quad\text{vs}\quad H_{1}:\rho_{g}(\mathcal{\mbox{\boldmath{$X$}}},Y)>0. (4) The null hypothesis in test ( 4 ) is equivalent to the null hypothesis of the K -sample test : \mathcal{H}_{0}^{\prime}:F_{1}=F_{2}=\cdots=F_{K}=F. In other words, this means that the distributions for each category, F_{1},F_{2},\ldots,F_{K} , are identical. We reject \mathcal{H}_{0} or \mathcal{H}_{0}^{\prime} when the observed value of \hat{\rho}_{g} is sufficiently large. Calculating the critical value for the test is challenging due to its dependence on unknown distribution parameters and the complex mixture distribution of the test statistic. To address this, as suggested by [ 1 ] , a permutation procedure is employed to estimate both the critical value and the p -value. We introduce the Python function independence_test to perform the independence test. 2.4 Generalized Categorical Gini Correlation For a nondegenerate random vector X in \mathbb{R}^{d} and a categorical variable Y , if E[||\mbox{\boldmath{$X$}}||^{\alpha}]<\infty for \alpha\in(0,2) , the generalized Gini correlation between X and Y is defined as: \rho_{g}(\mbox{\boldmath{$X$}},Y;\alpha)=\frac{\Delta(\alpha)-\sum_{k=1}^{K}p_{k}\Delta_{k}(\alpha)}{\Delta(\alpha)}. According to [ 1 ] , a computational consideration is the choice of \alpha , which is the parameter for the distance metric in \mathbb{R}^{d} . By their recommendation, a natural choice is \alpha=1 , corresponding to the Euclidean distance, which facilitates fast algorithms for the univariate case. However, in the presence of outliers, a smaller \alpha value is preferred to ensure that CGC remain insensitive to these outliers. 2.5 Illustrative example To demonstrate the applicability of the proposed CGC functions, we use the well-known IRIS dataset, which is widely used in machine learning and statistics. Originally introduced by the British biologist and statistician Ronald A. Fisher in 1936 for discriminant analysis, the dataset