Skip to content
Learn Netverks

Lesson

Step 10/36 28% through track

correlation-scipy

Correlation with SciPy

Last reviewed May 28, 2026 Content v20260528
Track mode
server_script
Means
Server runner
Reading
~1 min
Level
beginner

This lesson

This lesson teaches Correlation with SciPy: SciPy scientific routines on NumPy arrays—statistics, optimization, linear algebra, and numerical methods.

Teams apply Correlation with SciPy in every serious SciPy project—skipping it leaves blind spots in analysis and reviews.

You will apply Correlation with SciPy in contexts like: Research code, engineering simulations, and specialized analytics.

Read the narrative, run NumPy + SciPy snippets in the playground (install scipy and numpy with pip if needed), inspect outputs and convergence, and complete MCQs.

When you can explain the previous lesson's ideas in your own words.

stats.pearsonr measures linear association; stats.spearmanr uses ranks and handles nonlinear monotonic trends. Both return correlation and a p-value under null of no association.

Pearson vs Spearman

  • Pearson — linear relationship; sensitive to outliers
  • Spearman — monotonic relationship via ranks; more robust
  • Report r and p-value; visualize with scatter plot

Correlation ≠ causation

High correlation does not imply one variable causes another. Confounders and spurious time trends are common interview topics tied to Data Science literacy.

Example

import numpy as np
from scipy import stats

x = np.array([1, 2, 3, 4, 5], dtype=float)
y = np.array([2.1, 3.9, 6.2, 7.8, 10.1])
r, p = stats.pearsonr(x, y)
print('pearson r:', r, 'p:', p)

Important interview questions and answers

  1. Q: r near 0?
    A: Little linear association—nonlinear patterns may still exist; plot the data.
  2. Q: When Spearman?
    A: Ordinal data, rank-based relationships, or heavy outliers.

Self-check

  1. Difference between Pearson and Spearman?
  2. What two values does pearsonr return?

Pitfall: Pearson r measures linear fit—plot scatter before claiming association.

Interview prep

Pearson vs Spearman?

Pearson linear; Spearman rank/monotonic—more robust.

Causation?

Correlation does not imply causation—confounders matter.

Interview tip Lesson completion confidence

Can you explain this lesson in 30 seconds without reading notes?

Not saved yet.

Playground

Runs on the configured server runner (dev: npm run runner with LEARNING_RUNNER_ENABLED=true). Output appears below the editor.

Check yourself

Multiple choice — immediate feedback.

Discussion

Past discussion is visible to everyone. Only logged-in users can post comments and replies.

Starter discussion topics

  • Pearson vs Spearman?
  • p-value caution?

Sign up or log in to post comments and sync lesson progress across devices.

No discussion yet. Be the first to ask a question.

Jump