cancel
Showing results for 
Search instead for 
Did you mean: 
Community Platform Discussions
Connect with fellow community members to discuss general topics related to the Databricks platform, industry trends, and best practices. Share experiences, ask questions, and foster collaboration within the community.
cancel
Showing results for 
Search instead for 
Did you mean: 

Does databricks  support spearman rank correlation

chand20025
New Contributor

  while working on spark scala. I tried working on code using pearson correaltion it works but when I  tried to work on spearman rank correlation it displayed error like 

Currently only the calculation of the Pearson Correlation coefficient is supported.

Screenshot (21).png

 

1 REPLY 1

Kaniz_Fatma
Community Manager
Community Manager

Hi @chand20025

It seems that Databricks currently only supports the calculation of the Pearson Correlation coefficient and not the Spearman rank correlation. If you’re specifically looking to calculate Spearman rank correlation, you might need to explore alternative approaches or libraries.

One possible workaround is to use a common table expression (CTE) to compute the rank and then apply the corr() function on the result. Here’s an example in SQL:

WITH ranked_data AS (
    SELECT
        col1,
        col2,
        RANK() OVER (ORDER BY col1) AS rank_col1,
        RANK() OVER (ORDER BY col2) AS rank_col2
    FROM your_table
)
SELECT corr(rank_col1, rank_col2) AS spearman_correlation
FROM ranked_data;

This approach calculates the Spearman rank correlation by first ranking the data and then applying the correlation function. 

If you encounter any further issues or need additional assistance, feel free to ask! 😊

Connect with Databricks Users in Your Area

Join a Regional User Group to connect with local Databricks users. Events will be happening in your city, and you won’t want to miss the chance to attend and share knowledge.

If there isn’t a group near you, start one and help create a community that brings people together.

Request a New Group