Why perfectly dependent variables have so low pair level ? #998
DescriptionI found that when I run an unsupervised analysis with pairs enabled, pairs that are perfectly correlated have a rather low level. To reproduce: import numpy as np
import pandas as pd
from khiops import core as kh
# Generate data
# - When y == 0: X ~ Unif(0,1)
# - When y == 1: X ~ Unif(2,3)
np.random.seed(123)
n = 10000
x = np.concatenate([np.random.uniform(0, 1, n), np.random.uniform(2, 3, n)])
y = np.concatenate([np.zeros(n), np.ones(n)])
pd.DataFrame({"x": x, "y": y}).to_csv("data.csv", index=False)
# Unsupervised analysis with fast path
kh.train_predictor("", "", "data.csv", "", "report.khj", max_pairs=2)
# Print level
report = kh.read_analysis_results_file("report.khj")
print(report.bivariate_preparation_report.variables_pairs_statistics[0].level)
# 0.0402902I have also noted that for larger values of |
Replies: 5 comments
|
When analyzing a pair of variables (X, Y), Khiops exploits a co-clustering model M by partitioning each variable into intervals or groups of values according to their type, numerical or categorical. The resulting model cost, Cost(M), corresponds to the coding length of the co-clustering structure plus the coding length of both variables given the model: Cost(M) = CL(M) + CL(X|M) + CL(Y|M) The null model M₀ corresponds to the case of two independent variables, where the co-clustering reduces to a single co-cluster. The level of the pair can be interpreted as a compression rate: Level(M) = 1 - Cost(M) / Cost(M₀) This compression rate ranges between 0 and 1, is zero when the two variables are independent, and increases with the model's ability to capture the dependency structure. In an ideal case, with two identical variables, the co-clustering structure would perfectly encode the dependency, allowing one variable to be fully deduced from the other. However, encoding all values precisely is costly, and the compression rate is limited by the structure's ability to capture dependencies at a fine granularity. For example, in an experiment with two numerical variables and N=10,000, the dependency structure is captured with a co-clustering of K×K cells, with K=60. When one of the variables is Boolean, the co-clustering will consist of at most two parts per variable, which is too coarse to encode the values at a fine granularity. |
|
Thanks, I understand now why this happens. However, I thinks this render the Level more difficult to use as proxy for "good correlation" in this case, because Maybe this can be supplemented with other KPI's ? It comes to mind the ratio |
|
You are right, the Level of variable pairs is difficult to interpret:
But the suggested criterion based on mutual information (actually asymptotically similar to the level) cannot solve the problem. Perfectly dependent variables means that knowing the value of one variable, the value of the other can be perfectly derived. This will never be the case with two numerical variables. Note This problem is complex in the general case, and not tackled by any alternative method. Note The entropy of a numerical variable, known as differential entropy (cf. https://en.wikipedia.org/wiki/Entropy_(information_theory)#Entropy_for_continuous_random_variables), raises numerous problems. It corresponds to the transformation of a sum into an integral, in the limit where the bin size goes to zero. It can even be negative, and is therefore not exploitable in this context. More DetailsActually, the data part of the MDL criterion For pairs of categorical variables with few values, the asymptotic regime is rapidly attained, and the level increases towards 0.5 for identical variables, meaning that coding one variable is the same as coding both, once the dependence model is described and its coding length becomes negligible. For categorical variables involving many values, the asymptotic regime is not attained as quickly, resulting in a level significantly below 0.5. This is related to the uncertainty of the model, which needs to group values to increase frequencies, at the expense of a decayed fit of the data. For numerical variables, the problem is still more complex, as the asymptotic regime is never reached. With more data, more intervals are built, and more data is used to populate the contingency table between the parts of the two variables. One never reaches a point with a finite-sized variable partition (as with categorical variables), and can therefore never reach the asymptotic regime where the equality of two variables is exhaustively captured in the diagonal of the contingency table. |
|
Ok, got it. I still think the KPI remains difficult to interpret for pairs:
Maybe a KPI |
|
Thank you for the suggestion. Still, designing a theoretically sound, well-behaved, and useful KPI remains a complex and open challenge. |
When analyzing a pair of variables (X, Y), Khiops exploits a co-clustering model M by partitioning each variable into intervals or groups of values according to their type, numerical or categorical.
Observations are then assigned to the co-clustering cells to capture the dependency structure across the variables. Finally, the variables are described using this dependency structure.
The resulting model cost, Cost(M), corresponds to the coding length of the co-clustering structure plus the coding length of both variables given the model:
Cost(M) = CL(M) + CL(X|M) + CL(Y|M)
The null model M₀ corresponds to the case of two independent variables, where the co-clustering reduces to a single co-…