LoginSignup
3
3

More than 1 year has passed since last update.

【pandas-profiling/AutoViz/SweetViz 比較】EDAに役立つライブラリを比較してみた

Posted at

はじめに

データ分析/機械学習モデルを作成する時に欠かせないEDAですが、私はmatplotlibやseabornでグラフを作成する部分があまり得意ではないので、素早く網羅的にEDAするための有名なライブラリ3つ(pandas-profiring/autoviz/sweetviz)を使ってみて比較しました。
今回はタイタニックのデータを使用しています。

環境

  • Python 3.9.13
  • jupyter notebook 6.4.12
  • Numpy 1.21.5
  • Pandas 1.4.4
  • matplotlib 3.5.2
  • pandas-profiling 3.6.6
  • autoviz 0.1.601
  • sweetviz 2.1.4

サマリ

個人的な好みはAutoVizですが、どのライブラリも基本的な機能は揃っているのでお好みのライブラリを選択するのがいいと思います!

  • Pandas Profiling:最もシンプルでデータセットの概要を迅速にEDAが可能。

  • AutoViz:少し速度は遅い印象だが、目的変数と各特徴量の関係性がわかりやすい。特に、各特徴量のおすすめな前処理を教えてくれるのがとても良い!

  • Sweetviz:Pandas Profiling と同様の機能を持ちつつ、データセットの比較機能がついている。個人的にはモデル作成をする前に学習データとテストデータで偏りがないかを確認する際に使いたい。

出力結果(一部抜粋)

pandas-profiling

image.png

autoviz

image.png

sweetviz

image.png

実行コード

titanicデータの読み込み

titanic.ipynb
import pandas as pd
import numpy as np
%matplotlib inline
train = pd.read_csv("train.csv")
train

image.png

titanic.ipynb
target = 'Survived'
pandas-profiling.ipynb
!pip3 install pandas-profiling
from pandas_profiling import ProfileReport
profile = ProfileReport(train, title="Titanic data profiling Report")
profile

image.png

autoviz.ipynb
!pip3 install autoviz
from autoviz.AutoViz_Class import AutoViz_Class
AV = AutoViz_Class()
# depVarに目的変数、dfteにEDAしたいデータをセットする
dft = AV.AutoViz( "" ,sep=',', depVar=target, dfte=train, header=0, verbose=2,
lowess=False,chart_format='svg',max_rows_analyzed=1500,max_cols_analyzed=30)

image.png

sweetviz.ipynb
!pip3 install sweetviz
import sweetviz as sv
from sklearn.model_selection import train_test_split

# 学習データと評価データを作成
# train_test_splitの第一引数に特徴量、第二引数に目的変数を入れる。
x_train, x_test, y_train, y_test = train_test_split(train.iloc[:, 2:12], train.iloc[:, 1],test_size=0.2, random_state=1)

df_train = pd.concat([x_train, y_train], axis=1)
df_test = pd.concat([x_test, y_test], axis=1)

#ノートブックに直接表示
my_report = sv.compare([df_train, "Train"], [df_test, "Test"], target)
my_report.show_notebook()

image.png

最後に

最後までありがとうございました。

3
3
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
3
3