相关系数矩阵
pandas.DataFrame(数据).corr()
import pandas as pd
df = pd.DataFrame({
'a': [11, 22, 33, 44, 55, 66, 77, 88, 99],
'b': [10, 24, 30, 48, 50, 72, 70, 96, 90],
'c': [91, 79, 72, 58, 53, 47, 34, 16, 10],
'd': [99, 10, 98, 10, 17, 10, 77, 89, 10]})
df_corr = df.corr()
# 可视化
import matplotlib.pyplot as mp
import seaborn
seaborn.heatmap(df_corr, center=0, annot=True)
mp.show()
协方差矩阵
numpy.cov(数据)
import numpy as np
matric = [
[11, 22, 33, 44, 55, 66, 77, 88, 99],
[10, 24, 30, 48, 50, 72, 70, 96, 90],
[91, 79, 72, 58, 53, 47, 34, 16, 10],
[55, 20, 98, 19, 17, 10, 77, 89, 14]]
covariance_matrix = np.cov(matric)
# 可视化
print(covariance_matrix)
import matplotlib.pyplot as mp
import seaborn
seaborn.heatmap(covariance_matrix, center=0, annot=True, xticklabels=list('abcd'), yticklabels=list('ABCD'))
mp.show()
补充:
协方差
相关系数
来源:CSDN
作者:板儿爷
链接:https://blog.csdn.net/qq_39852676/article/details/103926553