0
0
SciPydata~30 mins

Pearson correlation in SciPy - Mini Project: Build & Apply

Choose your learning style9 modes available
Calculate Pearson Correlation with SciPy
📖 Scenario: You are analyzing how two sets of exam scores relate to each other. You want to find out if students who score high in one exam also score high in the other.
🎯 Goal: Calculate the Pearson correlation coefficient between two lists of exam scores using the scipy.stats library.
📋 What You'll Learn
Create two lists called exam1_scores and exam2_scores with exact values
Import the pearsonr function from scipy.stats
Use pearsonr to calculate the correlation coefficient between the two lists
Print the Pearson correlation coefficient value
💡 Why This Matters
🌍 Real World
Pearson correlation is used in many fields like education, health, and business to find relationships between two variables, such as test scores or sales numbers.
💼 Career
Data scientists and analysts use Pearson correlation to explore data and find meaningful patterns that help in decision making.
Progress0 / 4 steps
1
Create exam score lists
Create two lists called exam1_scores and exam2_scores with these exact values: exam1_scores = [85, 90, 78, 92, 88] and exam2_scores = [80, 95, 75, 90, 85].
SciPy
Need a hint?

Use square brackets to create lists and separate numbers with commas.

2
Import pearsonr function
Import the pearsonr function from the scipy.stats module.
SciPy
Need a hint?

Use the syntax from scipy.stats import pearsonr to import the function.

3
Calculate Pearson correlation
Use the pearsonr function with exam1_scores and exam2_scores as arguments. Store the first returned value (correlation coefficient) in a variable called correlation.
SciPy
Need a hint?

The pearsonr function returns two values: correlation and p-value. Use correlation, _ = pearsonr(...) to get only the correlation.

4
Print the Pearson correlation coefficient
Print the value of the variable correlation.
SciPy
Need a hint?

Use print(correlation) to display the result.