What is Correlation Matrix?
A correlation matrix is a table that shows the relationships between multiple variables.
It helps us understand how different variables are closely related to each other.
Each cell in the correlation matrix represents the correlation coefficient, which measures the strength and direction of the relationship between two variables.
- Correlation Coefficient
The correlation coefficient can range from -1 to 1.
Value = -1
A value of -1 indicates a strong negative relationship (as one variable increases, the other decreases)
Value = +1
A value of 1 indicates a strong positive relationship (both variables increase or decrease together),
Value = 0
0 value indicates no relationship between the variables.
Plotly Heatmap Correlation Matrix
An example of how you can use Plotly in Python to create a heatmap of a correlation matrix.
Here, we first generated a random correlation matrix using NumPy’s random.rand
function.
You can replace this with your actual correlation matrix.
import plotly.graph_objects as go import numpy as np # Generate a random correlation matrix np.random.seed(0) correlation_matrix = np.random.rand(5, 5) # Create the heatmap figure fig = go.Figure(data=go.Heatmap( z=correlation_matrix, x=['Variable 1', 'Variable 2', 'Variable 3', 'Variable 4', 'Variable 5'], y=['Variable 1', 'Variable 2', 'Variable 3', 'Variable 4', 'Variable 5'], colorscale='Viridis')) # Set the axis labels fig.update_layout( xaxis_title='X-axis', yaxis_title='Y-axis') # Show the figure fig.show()