当前位置:网站首页>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()
边栏推荐
- Dynamic effect of canvas lines
- 【Redis实现秒杀业务④】一人一单,不可重复购买
- Intensive reading of thinking about markdown
- Punch smart spirit 1. The brand is attractive. What is the strength of the product?
- 2019 summary and 2020 outlook
- Svg line animation background JS effect
- [interview question] what is a transaction? What are dirty reads, unrepeatable reads, phantom reads, and how to deal with several transaction isolation levels of MySQL
- 百公里加速仅5.92秒,威兰达高性能版以高能产品实力领跑
- Using tcp/udp tools to debug the yeelight ribbon
- 【排行榜】Carla leaderboard 排行榜 运行与参与手把手教学
猜你喜欢
UE4 WebBrowser chart cannot display problems
Kubernetes 架构核心组件工作原理解析
[distributed system design profile (2)] kV raft
5-minute NLP: summary of 3 pre training libraries for rapid realization of NER
Apk slimming compression experience
Infotnews | is the development of domestic NFT limited to digital collections?
Hyperledger Fabric 2. X dynamic update smart contract
传输层 以字节为单位的滑动窗口技术
2019 summary and 2020 outlook
Unimportant tokens can be stopped in advance! NVIDIA proposes an efficient visual transformer network a-vit with adaptive token to improve the throughput of the model
随机推荐
通过kubernetes可视化界面(rancher)安装kibana
传输层 以字节为单位的滑动窗口技术
ros(24):error: invalid initialization of reference of type ‘xx’ from expression of type ‘xx’
December 6, 2019 what happens after the browser enters a URL
Use of JMeter easynmon
无需显示屏的VNC Viewer远程连接树莓派
Interesting checkbox counters
[interview question] what is a transaction? What are dirty reads, unrepeatable reads, phantom reads, and how to deal with several transaction isolation levels of MySQL
【微服务|Sentinel】Sentinel快速入门|构建镜像|启动控制台
Custom animation (simulated win10 loading animation)
C# Winform 最大化遮挡任务栏和全屏显示问题
Tiktok wallpaper applet source code
How to reduce the font size of custom controls (optimize the round dot progress bar)
Virtual machine - network configuration
OTT营销之风正盛,商家到底该怎么投?
Do280openshift access control -- encryption and configmap
Go crawler framework -colly actual combat (II) -- Douban top250 crawling
Uniapp encapsulated incentive advertisement, screen insert advertisement and banner advertisement
2021-04-18
Apk slimming compression experience