LoginSignup
5
6

More than 5 years have passed since last update.

簡単に変数同士の相関係数を可視化する

Last updated at Posted at 2017-07-25

相関係数の一覧を表示する

kaggleのタイタニックの犠牲者データを使って、相関係数の一覧をheatmapを使って表示してみる
数値の値でしか確認できないので注意

corr.py
# lib install
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
%matplotlib inline 

train = pd.read_csv('./train.csv')
train.head()

2017-07-25_122911.png

corr.py
plt.figure(figsize=(8, 6)) #heatmap size
sns.heatmap(train.corr(), annot=True, cmap='plasma', linewidths=.5) # annot:値を表示するかどうか linewidths: しきり線

2017-07-25_123429.png

この例の場合、生き残ったかどうかが重要なので、Survivedの列を確認すると相関がある変数を見つけ出せますね

参考:Seaborn Heatmap

5
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
6