成人在线亚洲_国产日韩视频一区二区三区_久久久国产精品_99国内精品久久久久久久

您的位置:首頁(yè)技術(shù)文章
文章詳情頁(yè)

python seaborn heatmap可視化相關(guān)性矩陣實(shí)例

瀏覽:123日期:2022-07-23 10:04:36

方法

import pandas as pdimport numpy as npimport seaborn as snsdf = pd.DataFrame(np.random.randn(50).reshape(10,5))corr = df.corr()sns.heatmap(corr, cmap=’Blues’, annot=True)

python seaborn heatmap可視化相關(guān)性矩陣實(shí)例

將矩陣型簡(jiǎn)化為對(duì)角矩陣型:

mask = np.zeros_like(corr)mask[np.tril_indices_from(mask)] = Truesns.heatmap(corr, cmap=’Blues’, annot=True, mask=mask.T)

python seaborn heatmap可視化相關(guān)性矩陣實(shí)例

補(bǔ)充知識(shí):Python【相關(guān)矩陣】和【協(xié)方差矩陣】

相關(guān)系數(shù)矩陣

pandas.DataFrame(數(shù)據(jù)).corr()

import pandas as pddf = 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, seabornseaborn.heatmap(df_corr, center=0, annot=True, cmap=’YlGnBu’)mp.show()

python seaborn heatmap可視化相關(guān)性矩陣實(shí)例

協(xié)方差矩陣

numpy.cov(數(shù)據(jù))

import numpy as npmatric = [ [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, seabornseaborn.heatmap(covariance_matrix, center=0, annot=True, xticklabels=list(’abcd’), yticklabels=list(’ABCD’))mp.show()

python seaborn heatmap可視化相關(guān)性矩陣實(shí)例

補(bǔ)充

協(xié)方差

python seaborn heatmap可視化相關(guān)性矩陣實(shí)例

相關(guān)系數(shù)

python seaborn heatmap可視化相關(guān)性矩陣實(shí)例

EXCEL也能做

CORREL函數(shù)

python seaborn heatmap可視化相關(guān)性矩陣實(shí)例

以上這篇python seaborn heatmap可視化相關(guān)性矩陣實(shí)例就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持好吧啦網(wǎng)。

標(biāo)簽: Python 編程
相關(guān)文章: