Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Spearman correlation calculation #560

Closed
wants to merge 1 commit into from

Conversation

Ta7ar
Copy link
Contributor

@Ta7ar Ta7ar commented Jul 25, 2022

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:

  1. Robustness to outliers: When introduced an outlier in the 'petal length (cm)' column by 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]
  2. Detecting non-linear monotonic relationships: When introduced a new column as a exponential function of an old column by 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:

  • Find out how/where to store ranked_mean and ranked_var for spearman correlation merging/updates
  • Update ranked_mean and ranked_var on profile merging/updates
  • Update Spearman correlation on profile merging/updates
  • Write tests

@taylorfturner taylorfturner added Work In Progress Solution is being developed New Feature A feature addition not currently in the library labels Jul 25, 2022
@taylorfturner taylorfturner reopened this Aug 12, 2022
@JGSweets JGSweets changed the base branch from main to dev July 5, 2023 20:51
@taylorfturner taylorfturner deleted the branch capitalone:old-old-dev September 22, 2023 16:02
@taylorfturner taylorfturner reopened this Sep 26, 2023
@taylorfturner taylorfturner changed the base branch from old-dev to dev September 26, 2023 15:11
@taylorfturner taylorfturner changed the base branch from old-old-dev to dev January 11, 2024 18:17
@taylorfturner taylorfturner requested a review from a team as a code owner January 11, 2024 18:17
@taylorfturner taylorfturner deleted the branch capitalone:old-old-dev May 21, 2024 18:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
New Feature A feature addition not currently in the library Work In Progress Solution is being developed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants