Bird
0
0

What will be the output of this code?

medium📝 Predict Output Q5 of 15
SciPy - Statistical Tests
What will be the output of this code?
from scipy.stats import spearmanr
x = [3, 1, 4, 2, 5]
y = [10, 20, 30, 40, 50]
result = spearmanr(x, y)
print(round(result.correlation, 2))
A0.90
B0.70
C-0.90
D1.00
Step-by-Step Solution
Solution:
  1. Step 1: Understand Spearman correlation

    It measures the monotonic relationship between ranks of variables.
  2. Step 2: Rank the variables

    x ranks: [3,1,4,2,5] -> ranks [3,1,4,2,5]; y ranks: [10,20,30,40,50] -> ranks [1,2,3,4,5]
  3. Step 3: Calculate correlation of ranks

    Ranks of x and y are positively correlated but not perfectly, resulting in about 0.9.
  4. Final Answer:

    0.90 -> Option A
  5. Quick Check:

    Monotonic increasing but not perfect [OK]
Quick Trick: Spearman correlates ranks, not raw values [OK]
Common Mistakes:
MISTAKES
  • Assuming perfect correlation when ranks differ
  • Confusing Pearson with Spearman correlation
  • Ignoring the rank transformation step

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SciPy Quizzes