当前位置:网站首页>Thermodynamic diagram display correlation matrix
Thermodynamic diagram display correlation matrix
2022-06-25 00:43:00 【Dream painter】
The Pearson correlation coefficient is usually used to quantify the relationship between two variables , That is to measure the linear correlation between variables .
Value range of correlation coefficient :[-1,1]:
- -1 Indicates a completely negative linear correlation
- 0 Indicates that there is no linear relationship
- 1 Indicates a completely positive linear correlation
The farther away 0, The stronger the correlation . When the number of variables exceeds 2 Time , The correlation matrix is usually used to represent , That is, the correlation between each pair of variables is expressed in the form of square matrix .
Pass below Python An example shows how to calculate the correlation matrix , And use the thermodynamic diagram to represent .
Create correlation matrix
First create the sample data set :
import pandas as pd
data = {'assists': [4, 5, 5, 6, 7, 8, 8, 10],
'rebounds': [12, 14, 13, 7, 8, 8, 9, 13],
'points': [22, 24, 26, 26, 29, 32, 20, 14]
}
df = pd.DataFrame(data, columns=['assists','rebounds','points'])
df
# assist rebounds points
# 0 4 12 22
# 1 5 14 24
# 2 5 13 26
# 3 6 7 26
# 4 7 8 29
# 5 8 8 32
# 6 8 9 20
# 7 10 13 14
Let's calculate the correlation matrix :
# Create correlation matrix
df.corr()
# assists rebounds points
# assists 1.000000 -0.244861 -0.329573
# rebounds -0.244861 1.000000 -0.522092
# points -0.329573 -0.522092 1.000000
# Create correlation matrix , Keep three decimal places
df.corr().round(3)
# assists rebounds points
# assists 1.000 -0.245 -0.330
# rebounds -0.245 1.000 -0.522
# points -0.330 -0.522 1.000
The correlation coefficients of the diagonals of the table are 1, Indicates that each variable is completely autocorrelated . Other values represent the correlation coefficient of each pair of variables :
assists and rebounds The correlation coefficient is 0 -0.245.
assists and points The correlation coefficient is 0 -0.330.
rebounds and points The correlation coefficient is 0 -0.522.
Visualization of correlation matrix
Hypomorphism pandas Visual correlation matrix of style selection in package , Use different styles :
corr = df.corr()
sns.heatmap(corr, xticklabels=corr.columns, yticklabels=corr.columns, cmap="Blues")
# sns.heatmap(corr, xticklabels=corr.columns, yticklabels=corr.columns, cmap="RdYlGn")
# sns.heatmap(corr, xticklabels=corr.columns, yticklabels=corr.columns, cmap="coolwarm")
# sns.heatmap(corr, xticklabels=corr.columns, yticklabels=corr.columns, cmap="bwr")
# sns.heatmap(corr, xticklabels=corr.columns, yticklabels=corr.columns, cmap="PuOr")
plt.title(' Correlation thermogram ')
plt.show()
| 

Complete code
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
plt.rcParams["font.sans-serif"] = ["SimHei"]
plt.rcParams['axes.unicode_minus'] = False
data = {'assists': [4, 5, 5, 6, 7, 8, 8, 10],
'rebounds': [12, 14, 13, 7, 8, 8, 9, 13],
'points': [22, 24, 26, 26, 29, 32, 20, 14]
}
df = pd.DataFrame(data, columns=['assists', 'rebounds', 'points'])
corr = df.corr()
sns.heatmap(corr, xticklabels=corr.columns, yticklabels=corr.columns, cmap="Blues")
# sns.heatmap(corr, xticklabels=corr.columns, yticklabels=corr.columns, cmap="RdYlGn")
# sns.heatmap(corr, xticklabels=corr.columns, yticklabels=corr.columns, cmap="coolwarm")
# sns.heatmap(corr, xticklabels=corr.columns, yticklabels=corr.columns, cmap="bwr")
# sns.heatmap(corr, xticklabels=corr.columns, yticklabels=corr.columns, cmap="PuOr")
plt.title(' Correlation thermogram ')
plt.show()
边栏推荐
- Collection of software testing and game testing articles
- Uniapp encapsulated incentive advertisement, screen insert advertisement and banner advertisement
- ros(24):error: invalid initialization of reference of type ‘xx’ from expression of type ‘xx’
- Source code analysis the problem that fragments cannot be displayed in the custom ViewGroup
- 【Redis实现秒杀业务②】超卖问题的解决方案
- Do280openshift access control -- encryption and configmap
- Fuxin Kunpeng joins in, and dragon lizard community welcomes a new partner in format document technical service
- Qiniu cloud uploads video to get the first frame of video
- 热力图展示相关矩阵
- Go crawler framework -colly actual combat (4) -- Zhihu answer crawl (2) -- visual word cloud
猜你喜欢

ros(25):rqt_ image_ View reports an error unable to load plugin for transport 'compressed', error string

Color gradient gradient color collection

A small program written this week

C# Winform 最大化遮挡任务栏和全屏显示问题

Svg line animation background JS effect
Design and practice of vivo server monitoring architecture
Is it so difficult to calculate the REM size of the web page according to the design draft?

离散数学及其应用 2018-2019学年春夏学期期末考试 习题详解
Paper review: U2 net, u-net composed of u-net

Use of JMeter
随机推荐
Fuxin Kunpeng joins in, and dragon lizard community welcomes a new partner in format document technical service
Jar package merging using Apache ant
ServerSocket and socket connection
打卡smart精灵#1,品牌不缺吸引力,产品本身实力如何?
Source code analysis the problem that fragments cannot be displayed in the custom ViewGroup
Decoupling pages and components using lifecycle
Uniapp encapsulated incentive advertisement, screen insert advertisement and banner advertisement
What is the difference between one way and two way ANOVA analysis, and how to use SPSS or prism for statistical analysis
融合模型权限管理设计方案
ros(25):rqt_image_view报错Unable to load plugin for transport ‘compressed‘, error string
[figure database performance and scenario test sharp tool ldbc SNB] series I: introduction to data generator & Application to ges service
Registration method of native method in JNI
Hyperledger Fabric 2. X dynamic update smart contract
[proteus simulation] example of using timer 0 as a 16 bit counter
Go crawler framework -colly actual combat (III) -- panoramic cartoon picture capture and download
Signal integrity (SI) power integrity (PI) learning notes (I) introduction to signal integrity analysis
Kibana installation via kubernetes visual interface (rancher)
ros(25):rqt_ image_ View reports an error unable to load plugin for transport 'compressed', error string
Use of JMeter
Use of navigation and navigationui