3 Awesome Visualization Techniques for every dataset
By: Rahul Agarwal
Tags: Education, Data Visualization, Data Science, Towards Data Science, Python

Categorical Correlation with Graphs:

In Simple terms, Correlation is a measure of how two variables move together.

For example, In the real world, Income and Spend are positively correlated. If one increases the other also increases.

Academic Performance and Video Games Usage is negatively correlated. Increase in one predicts a decrease in another.

So if our predictor variable is positively or negatively correlated with our target variable, it is valuable.

Correlations among different variables are a pretty good thing to do when we try to understand our data.

We can create a pretty good correlation plot using Seaborn easily.

Where did all the categorical variables go?

But do you notice any problem?

Yes, this graph only calculates Correlation between Numerical columns.

What if my target variable is Club or Position?

I want to be able to get a correlation among three different cases, and we use the following metrics of correlation to calculate these:

1. Numerical Variables

We already have this in the form of Pearson’s Correlation which is a measure of how two variables move together. This Ranges from [-1,1]

2. Categorical Variables

We will use Cramer’s V for categorical-categorical cases. It is the intercorrelation of two discrete variables and used with variables having two or more levels. It is a symmetrical measure as in the order of variable does not matter. Cramer(A,B) == Cramer(B,A).

For Example: In our dataset, Club and Nationality must be somehow correlated.

Let us check this using a stacked graph which is an excellent way to understand distribution between categorical vs. categorical variables. We use a subset of data since there are a lot of nationalities and club in this data.

We keep only the best teams(Kept FC Porto just for more diversity in the sample)and the most common nationalities.

Club preference says quite a bit about Nationality: knowing the former helps a lot in predicting the latter.

We can see if a player belongs to England, it is more probable he plays in Chelsea or Manchester United and not in FC Barcelona or Bayern Munchen or Porto.

So there is some information present here. Cramer’s V captures the same information.

If all clubs have the same proportion of players from every nationality, Cramer’s V is 0.

If Every club prefers a single nationality Cramer’s V ==1, for example, all England player play in Manchester United, All Germans in Bayern Munchen and so on.

In all other cases, it ranges from [0,1]

3. Numerical and Categorical variables

We will use the Correlation Ratio for categorical-continuous cases.

Without getting into too much Maths, it is a measure of Dispersion.

Given a number can we find out which category it belongs to?

For Example:

Suppose we have two columns from our dataset: SprintSpeed and Position :

GK: 58(De Gea),52(T. Courtois), 58(M. Neuer), 43(G. Buffon)

58(De Gea),52(T. Courtois), 58(M. Neuer), 43(G. Buffon) CB: 68(D. Godin), 59(V. Kompany), 73(S. Umtiti), 75(M. Benatia)

68(D. Godin), 59(V. Kompany), 73(S. Umtiti), 75(M. Benatia) ST: 91(C.Ronaldo), 94(G. Bale), 80(S.Aguero), 76(R. Lewandowski)

As you can see these numbers are pretty predictive of the bucket they fall into and thus high Correlation Ratio.

If I know the sprint speed is more than 85, I can definitely say this player plays at ST.

This ratio also ranges from [0,1]