[WIP] Spearman correlation calculation #560
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Enables DataProfiler to calculate Spearman correlation with the options to allow users to enable/disable calculations or specify columns for calculations.
When ran on
Iris
dataset, the Pearson correlation and the Spearman correlation are very similar (as it should be when correlations are linear),'correlation_matrix': array([[ 1. , -0.11756978, 0.87175378, 0.81794113, 0.78256123], [-0.11756978, 1. , -0.4284401 , -0.36612593, -0.42665756], [ 0.87175378, -0.4284401 , 1. , 0.96286543, 0.9490347 ], [ 0.81794113, -0.36612593, 0.96286543, 1. , 0.95654733], [ 0.78256123, -0.42665756, 0.9490347 , 0.95654733, 1. ]]), 'spearman_correlation_matrix': array([[ 1. , -0.16677766, 0.88189813, 0.83428878, 0.79807812], [-0.16677766, 1. , -0.30963509, -0.28903175, -0.44028958], [ 0.88189813, -0.30963509, 1. , 0.93766682, 0.93543052], [ 0.83428878, -0.28903175, 0.93766682, 1. , 0.93817917], [ 0.79807812, -0.44028958, 0.93543052, 0.93817917, 1. ]]),
Spearman mainly has 2 advantages over Pearson:
iris['petal length (cm)'][random_index] = 100
, Pearson correlation of the column changes drastically from,[ 0.87175378, -0.4284401 , 1. , 0.96286543, 0.9490347 ] to [ 0.23429883, -0.0503025 , 1. , 0.34474503, 0.30366187]
Whereas Spearman correlation of the column changes from,
[ 0.88189813, -0.30963509, 1. , 0.93766682, 0.93543052] to [ 0.88048828, -0.30861155, 1. , 0.9383322 , 0.93542968]
iris['exp'] = iris.apply(lambda row: row['petal length (cm)']**10, axis=1)
, the Pearson correlation between columns 'exp' and 'petal length (cm)' is 0.56452528 whereas Spearman correlation is 1.Todo: