0
0
NumPydata~15 mins

Correlation coefficient with np.corrcoef() in NumPy - Mini Project: Build & Apply

Choose your learning style9 modes available
Correlation coefficient with np.corrcoef()
📖 Scenario: You are a data analyst working with sales data. You want to find out how two products' sales numbers move together. This helps you understand if when one product sells more, the other also sells more or less.
🎯 Goal: Calculate the correlation coefficient between two products' sales using np.corrcoef() to see how their sales relate.
📋 What You'll Learn
Create two lists of sales numbers for Product A and Product B
Create a variable to hold these sales lists
Use np.corrcoef() to calculate the correlation coefficient matrix
Extract the correlation coefficient value between Product A and Product B
Print the correlation coefficient value
💡 Why This Matters
🌍 Real World
Correlation helps businesses understand relationships between sales of different products, guiding marketing and stocking decisions.
💼 Career
Data analysts and scientists use correlation coefficients to find patterns and relationships in data, which supports better decision-making.
Progress0 / 4 steps
1
Create sales data lists
Create two lists called sales_product_a and sales_product_b with these exact values: sales_product_a = [10, 20, 30, 40, 50] and sales_product_b = [15, 25, 35, 45, 55].
NumPy
Need a hint?

Use square brackets [] to create lists with the exact numbers given.

2
Import numpy library
Import the numpy library using import numpy as np to use the correlation function.
NumPy
Need a hint?

Type import numpy as np at the top of your code.

3
Calculate correlation coefficient matrix
Use np.corrcoef() with sales_product_a and sales_product_b as arguments and save the result in a variable called correlation_matrix.
NumPy
Need a hint?

Call np.corrcoef() with the two sales lists inside the parentheses.

4
Print the correlation coefficient
Print the correlation coefficient between Product A and Product B by accessing the value at row 0, column 1 of correlation_matrix using correlation_matrix[0, 1].
NumPy
Need a hint?

Use print(correlation_matrix[0, 1]) to show the correlation coefficient.