It measures the strength and direction of a linear relationship between two variables, ranging from -1 (perfect negative) to 1 (perfect positive).
Click to reveal answer
beginner
What is the purpose of np.corrcoef() in numpy?
It calculates the correlation coefficient matrix between input arrays, showing how variables relate linearly.
Click to reveal answer
beginner
How do you interpret a correlation coefficient of 0?
It means there is no linear relationship between the two variables, but they might still have other types of relationships.
Click to reveal answer
intermediate
What shape of output does np.corrcoef() return when given two 1D arrays?
It returns a 2x2 matrix where diagonal elements are 1 (correlation of each variable with itself) and off-diagonal elements are the correlation coefficients between the two variables.
Click to reveal answer
intermediate
Why is it important to check correlation before building a predictive model?
Because strong correlations can indicate important relationships between variables, helping to select features and understand data patterns.
Click to reveal answer
What is the range of values for the correlation coefficient?
A-1 to 1
B0 to 1
C-100 to 100
D0 to infinity
✗ Incorrect
The correlation coefficient ranges from -1 (perfect negative) to 1 (perfect positive).
What does np.corrcoef(x, y) return when x and y are 1D arrays?
AA list of correlation values
BA single correlation value
CA 2x2 matrix of correlation coefficients
DAn error
✗ Incorrect
It returns a 2x2 matrix showing correlations between x and y and themselves.
If the correlation coefficient between two variables is close to 0, what does it mean?
ANo linear relationship
BStrong positive relationship
CStrong negative relationship
DPerfect correlation
✗ Incorrect
A value near 0 means no linear relationship between variables.
Which numpy function is used to calculate correlation coefficients?
How would you use np.corrcoef() to find if the temperatures in the two cities move together, and what does the off-diagonal value represent?
hard
A. Use np.corrcoef(city1); off-diagonal is correlation with itself
B. Use np.corrcoef(city1 + city2); off-diagonal is sum of temperatures
C. Use np.corrcoef(city1 * city2); off-diagonal is product correlation
D. Use np.corrcoef(city1, city2); off-diagonal is correlation between city1 and city2 temperatures
Solution
Step 1: Apply np.corrcoef to two arrays
Pass both city1 and city2 arrays as separate arguments: np.corrcoef(city1, city2).
Step 2: Interpret the off-diagonal value
The off-diagonal value in the resulting matrix shows the correlation coefficient between the two cities' temperatures, indicating how they move together.
Final Answer:
Use np.corrcoef(city1, city2); off-diagonal is correlation between city1 and city2 temperatures -> Option D
Quick Check:
Off-diagonal = correlation between two arrays [OK]
Hint: Off-diagonal in np.corrcoef matrix shows correlation between inputs [OK]
Common Mistakes:
Passing combined arrays instead of separate ones
Misunderstanding off-diagonal meaning
Using single array input expecting two-variable correlation
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.