ペアの生成と比較

Rでのデータクリーニング

Maggie Matsui

Content Developer @ DataCamp

結合(join)が効かないとき

左の表は event と time。例: Houston Rockets vs Chicago Bulls 19:00、Miami Heat vs Los Angeles Lakers 19:00、Brooklyn Nets vs Orlando Magic 20:00、Denver Nuggets vs Miami Heat 21:00、San Antonio Spurs vs Atlanta Hawks 21:00。右の表は: NBA: Nets vs Magic 8pm、NBA: Bulls vs Rockets 9pm、NBA: Heat vs Lakers 7pm、NBA: Grizzlies vs Heat 10pm、NBA: Heat vs Cavaliers 9pm。

Rでのデータクリーニング

結合(join)が効かないとき

Rでのデータクリーニング

レコードリンケージとは?

左にほうきを持つ2つのデータベース。ラベルは Data A と Data B

Rでのデータクリーニング

レコードリンケージとは?

左に、ほうきを持つ2つのデータベース(Data A と Data B)

Rでのデータクリーニング

レコードリンケージとは?

Data A と Data B から、3組の人物へ矢印。ラベルは「ペア生成」。

Rでのデータクリーニング

レコードリンケージとは?

「ペア生成」から、相互に矢印が向く2列の円へ矢印。説明は「ペアを比較」。

Rでのデータクリーニング

レコードリンケージとは?

「ペア比較」から、.93 と書かれた札を掲げる人物へ矢印。ラベルは「ペアにスコア」。

Rでのデータクリーニング

レコードリンケージとは?

「スコア付け」から鎖へ矢印。ラベルは「データをリンク」。

Rでのデータクリーニング

レコードリンケージとは?

同じ図で「ペア生成」手順を青枠で強調

Rでのデータクリーニング

レコードのペア

2つの表 df_A と df_B(氏名・郵便番号・州)。df_A の Keaton Z Snyder(15020, PA)と、df_B の Keaton Snyder(15020, PA)の行を強調。

Rでのデータクリーニング

ペアの生成

同じ表で、df_A の各行から df_B の各行へ全組合せの線を表示。

Rでのデータクリーニング

Rでのペア生成

library(reclin)
pair_blocking(df_A, df_B)
Simple blocking
  No blocking used.
  First data set:  5 records
  Second data set: 5 records
  Total number of pairs: 25 pairs

ldat with 25 rows and 2 columns x y 1 1 1 2 2 1 3 3 1 ...
Rでのデータクリーニング

ペアが多すぎる

同じ表を下に拡張し行数増。さらに多数の線で全組合せを接続。

Rでのデータクリーニング

ブロッキング

同じ表だが、州が一致する行だけ線で接続。

ブロッキング変数(State)が一致するペアのみ考慮

Rでのデータクリーニング

Rでのペア・ブロッキング

pair_blocking(df_A, df_B, blocking_var = "state")
Simple blocking                                 ldat with 8 rows and 2 columns
  Blocking variable(s): state                     x y
  First data set:  5 records                    1 1 1
  Second data set: 5 records                    2 1 4
  Total number of pairs: 8 pairs                3 2 3
                                                4 2 5
                                                5 3 2
                                                6 4 2
                                                7 5 1
                                                8 5 4
Rでのデータクリーニング

ペアの比較

レコードリンケージ手順の図で「ペア比較」を強調。

Rでのデータクリーニング

ペアの比較

pair_blocking(df_A, df_B, blocking_var = "state") %>%

compare_pairs(by = "name", default_comparator = lcs())
Compare                                     ldat with 8 rows and 3 columns            
  By: name                                      x y      name
                                              1 1 1 0.3529412
Simple blocking                               2 1 4 0.3030303
  Blocking variable(s): state                 3 2 3 0.9285714
  First data set:  5 records                  4 2 5 0.2962963    
  Second data set: 5 records                  ...
  Total number of pairs: 8 pairs              8 5 4 0.3333333
Rでのデータクリーニング

複数列の比較

pair_blocking(df_A, df_B, blocking_var = "state") %>%
  compare_pairs(by = c("name", "zip"), default_comparator = lcs())
Compare                                    ldat with 8 rows and 4 columns
  By: name, zip                              x y      name zip
                                           1 1 1 0.3529412 0.4
Simple blocking                            2 1 4 0.3030303 0.2
  Blocking variable(s): state              3 2 3 0.9285714 1.0
  First data set:  5 records               4 2 5 0.2962963 0.2
  Second data set: 5 records               ...
  Total number of pairs: 8 pairs           8 5 4 0.3333333 0.2
Rでのデータクリーニング

異なるコンパレータ

  • default_comparator = lcs()
  • default_comparator = jaccard()
  • default_comparator = jaro_winkler()
Rでのデータクリーニング

Ayo berlatih!

Rでのデータクリーニング

Preparing Video For Download...