Correlation Analysis: How to Build a Correlation Matrix for Mixed Data Types
Correlation analysis measures how strongly pairs of variables move together, and the right measure depends on the column types: Pearson or Spearman for two numeric columns, Cramér's V for two categorical columns and the correlation ratio (eta) for a categorical and a numeric column. TensorTurn computes a mixed-type association matrix over every column pair automatically when you upload a dataset, lists the top correlated pairs and lets you open a scatter plot, so you can spot redundancy and leakage before you train a model.
What correlation tells you, and what it does not
A correlation coefficient summarizes the strength of a relationship between two variables in a single number, usually between -1 and 1 for signed measures or between 0 and 1 for association measures. It is a quick way to find redundant features, candidate predictors and data problems. It does not tell you why two variables move together, whether the relationship holds outside your sample or whether it is linear unless you chose a measure that assumes linearity.
Choosing the right correlation measure
| Measure | Column types | Range | Captures | Watch out for |
|---|---|---|---|---|
| Pearson r | Numeric and numeric | -1 to 1 | Linear relationships | Sensitive to outliers and skew; misses curved relationships |
| Spearman rho | Numeric or ordinal pairs | -1 to 1 | Monotonic relationships via ranks | Misses non-monotonic patterns such as U shapes |
| Cramér's V (bias-corrected) | Categorical and categorical | 0 to 1 | Any association between categories | Uncorrected V is inflated with many categories and small samples |
| Correlation ratio (eta) | Categorical and numeric | 0 to 1 | How much the numeric mean differs across categories | Rare categories with few rows can exaggerate it |
Pearson is the default in most spreadsheet and notebook tools, but it only applies to numeric pairs. Spearman ranks the values first, which makes it robust to outliers and able to capture any monotonic trend. Cramér's V is derived from the chi-square statistic of a contingency table; the bias-corrected version adjusts for the tendency of plain V to report association where there is none when categories are many and rows are few. The correlation ratio eta compares the variance of category means to the total variance of the numeric column, so an eta near 1 means the category almost determines the number.
Why mixed-type correlation matters
Real datasets are rarely all numeric. Customer tables have plan type, region and channel; transaction tables have merchant category and payment method. If you run a standard correlation matrix, those columns silently drop out, and you miss both your strongest predictors and your most dangerous leaks. One-hot encoding them first is not a good substitute either: a single categorical column becomes dozens of sparse dummy columns with weak individual correlations, which hides the overall relationship.
A mixed-type association matrix puts every pair on a comparable 0 to 1 strength scale. TensorTurn uses Pearson for numeric pairs, bias-corrected Cramér's V for categorical pairs and the correlation ratio for categorical-numeric pairs, so a plan-type column and a monthly-charges column appear in the same view as two numeric columns. Keep in mind that the measures are not identical in meaning, so compare them as strength signals rather than as exactly interchangeable numbers.
Correlation is not causation
Ice cream sales correlate with drowning incidents because both rise in hot weather. In business data, the same trap shows up constantly: support tickets correlate with churn, but tickets may be a symptom of a bad product experience rather than a cause. For prediction, that is often fine, because a model only needs reliable signal. For decisions, such as 'reduce tickets to reduce churn', correlation alone is not evidence. Confounders, reverse causation and selection effects all produce strong correlations without a causal link.
Multicollinearity: when features are too correlated with each other
When two or more features are highly correlated with each other, models struggle to separate their effects. Linear and logistic regression coefficients become unstable and hard to interpret, and feature importance gets split arbitrarily between twins. Tree-based models such as XGBoost and LightGBM are less affected in accuracy, but their importance rankings still become misleading. Practical fixes:
- Drop one of each highly correlated pair, keeping the one that is cleaner or easier to obtain at prediction time.
- Combine them into a single feature, such as a ratio or an average.
- Use regularization (ridge or lasso) for linear models.
- For a stricter check than pairwise correlation, compute variance inflation factors in a notebook; values above roughly 5 to 10 are a common warning sign.
Leakage hides behind suspiciously high correlation
The most valuable use of a correlation matrix before training is catching target leakage. If a feature is almost perfectly associated with the label, ask when it was recorded. A 'cancellation_reason' column correlates perfectly with churn because it only exists for churned customers. A 'days_in_collections' column predicts default because it is filled in after the default happens. These features produce spectacular validation scores and useless production models. TensorTurn surfaces the top correlated pairs and, when you pick a target, adds explicit leakage flags for features that are suspiciously predictive, so you can drop them before they fool you.
How to run correlation analysis on TensorTurn
- Upload your CSV, Excel, Parquet or JSON file; the association matrix is computed in your browser on upload.
- Scan the matrix and the top correlated pairs list for redundant features and unexpected relationships.
- Open the scatter plot for any numeric pair to check whether the relationship is linear, curved or driven by a few outliers.
- Select your target column to see per-feature predictive signal and leakage flags.
- Drop or combine redundant and leaky columns in the AI data editor by describing the change, then approve the steps.
- If you need Spearman or VIF specifically, ask for them in the generated training notebook, which is standard Python with pandas and scikit-learn available.
Frequently asked questions
What is the difference between Pearson and Spearman correlation?
Pearson measures linear relationships between raw numeric values and is sensitive to outliers. Spearman correlates the ranks of the values, so it captures any monotonic relationship and is more robust to outliers and skew.
How do you calculate correlation between categorical variables?
Use Cramér's V, which is based on the chi-square statistic of the contingency table and ranges from 0 (no association) to 1 (perfect association). The bias-corrected version is preferable when there are many categories or few rows.
How do you correlate a categorical and a numeric variable?
Use the correlation ratio (eta), which compares how much the numeric column's mean varies across categories to its total variance. An eta close to 1 means the category almost determines the numeric value.
What correlation is too high between features?
There is no universal cutoff, but pairs above about 0.8 to 0.9 are usually redundant and worth reviewing. A feature with near-perfect association with the target is more often leakage than a genuine predictor.
Does TensorTurn compute Spearman correlation?
TensorTurn's automatic matrix uses Pearson for numeric pairs, bias-corrected Cramér's V for categorical pairs and the correlation ratio for mixed pairs. Spearman can be computed in the generated Python notebook if you ask for it.