0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

データ解析で避けて通れないのが欠損値の問題。今回は、Pythonのmissingnoライブラリを使って、データセットの欠損値を可視化する方法を紹介します。Kaggleのタイタニックデータセットを例に取り、具体的な使い方を解説します。

欠損値の種類

  • MCAR(完全にランダムに欠損)
  • MAR(条件付きでランダムに欠損)
  • MNAR(ランダムでない欠損)

データの準備

kaggleのtitanicデータを使用して可視化してみます。まずはライブラリをインポートし、データを読み込みます。

titanicのデータはkaggleから予めダウンロードしています(ファイル名:train.csv)

#ライブラリのインポート
import pandas as pd
import missingno as msno

#データをロード
train=pd.read_csv('train.csv')
train.head()

image.png

可視化の方法

バーグラフ:全体の欠損状況を一目で把握。

import missingno as msno
msno.bar(df)

image.png

マトリックス:データのパターンを視覚化。

msno.matrix(df)

image.png

デンドログラム:変数間の相関を見つける。

msno.dendrogram(df)

image.png

ヒートマップ:欠損値の相関関係を把握。

msno.heatmap(df)

image.png

まとめ

欠損値の可視化により、データの前処理がスムーズに進み、解析の精度が向上します。missingnoライブラリを活用して、欠損データのパターンを理解し、より良いデータ解析を目指しましょう!

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?