0

# Spearman's Rank Correlation Coefficient

Unsolved
###### Prob. and Stats

Difficulty: 1 | Problem written by Junaid Ahmed
A quantitative metric of the linearity of a relation between two datasets is the Spearman rank-order correlation coefficient:

$$r_{s} = 1 - \frac{6\sum d_{i}^{2}}{n(n^{2}-1)}$$

d is the difference between the two data points

n is the total number of observations

Write a Python function to implement the Spearman rank-order correlation coefficient.

Input

d, n

Output

Correlation coefficient

##### Sample Input:
<class 'float'>
d1: 0.2
<class 'float'>
d2: 0.4
<class 'float'>
d3: 0.5
<class 'int'>
n: 2

##### Expected Output:
<class 'float'>
0.55

MLPro Premium also allows you to access all our high quality MCQs which are not available on the free tier.

Not able to solve a problem? MLPro premium brings you access to solutions for all problems available on MLPro

Have an issue, the MLPro support team is available 24X7 to Premium users.

##### This is a premium feature. To access this and other such features, click on upgrade below.

uozcan12 • 5 months, 3 weeks ago

0

I applied this and I've got 0.55 but expected score seems 0.66. But what should I do?

#!/usr/bin/python3

# Please do not change the below function name and parameters
def sR(d1,d2,d3,n):
d_square_sum = d1**2 + d2**2 + d3**2
divided_by = n*((n**2)-1)
division_part = (6*d_square_sum)
return 1-(division_part/divided_by)