Phát hiện dữ liệu không nhất quán

Làm sạch dữ liệu trong cơ sở dữ liệu PostgreSQL

Darryl Reeves, Ph.D.

Industry Assistant Professor, New York University

Dữ liệu không nhất quán

  • Một số quy tắc kiểm tra nhà hàng
  • score tương ứng số vi phạm 2_4_hazard
    camis    |              name               |  score | ... 
    ---------+---------------------------------+--------+-----
    ...      | ...                             | ...    | ...                                   
    41659848 | LA BRISA DEL CIBAO              | 20     | ...
    40961447 | MESON SEVILLA RESTAURANT        | 50     | ...
    50063071 | WA BAR                          | 15     | ...
    ...      | ...                             | ...    | ...
    
  • A (0 đến 13), B (14 đến 27), C (28+)
  • Kịch bản xếp hạng:
    • A ở lần kiểm tra đầu
    • Tái kiểm tra có thể A, B, hoặc C
1 https://www1.nyc.gov/assets/doh/downloads/pdf/rii/restaurant-grading-faq.pdf
Làm sạch dữ liệu trong cơ sở dữ liệu PostgreSQL

Kiểm tra quy tắc với SQL

  • Phụ thuộc lẫn nhau có thể gây không nhất quán
  • Có thể mã hóa quy tắc trong SQL
  • A áp cho điểm từ 0 đến 13
SELECT 
    camis, 
    grade, 
    grade_date, 
    score, 
    inspection_type 
FROM 
    restaurant_inspection 
WHERE 
    grade = 'A' AND 
    score NOT BETWEEN 0 AND 13;
0
Làm sạch dữ liệu trong cơ sở dữ liệu PostgreSQL

Kiểm tra quy tắc với SQL

  • B áp cho điểm từ 14 đến 27
SELECT 
    camis, 
    grade, 
    grade_date, 
    score, 
    inspection_type 
FROM 
    restaurant_inspection 
WHERE 
    grade = 'B' AND 
    score NOT BETWEEN 14 AND 27;
 camis    | grade | grade_date | score |         inspection_type          
 ---------+-------+------------+-------+----------------------------------
 50034653 | B     | 12/06/2019 | -1    | Cycle Inspection / Re-inspection
Làm sạch dữ liệu trong cơ sở dữ liệu PostgreSQL

Kiểm tra quy tắc với SQL

SELECT 
    camis, grade, grade_date, score, inspection_type FROM 
    restaurant_inspection 
WHERE 
    (grade = 'A' OR grade = 'B' OR grade = 'C') AND
    inspection_type LIKE '%Reopening%';
 camis    | grade | grade_date | score |                 inspection_type                 | ... 
 ---------+-------+------------+-------+-------------------------------------------------+-----
 ...      | ...   | ...        | ...   | ...                                             | ...
 50005784 | C     | 05/29/2019 | 14    | Cycle Inspection / Reopening Inspection         | ...
 50091190 | C     | 07/12/2019 | 7     | Pre-permit (Operational) / Reopening Inspection | ...
 40395023 | C     | 09/13/2019 | 8     | Cycle Inspection / Reopening Inspection         | ...
 50037770 | C     | 10/26/2018 | 11    | Cycle Inspection / Reopening Inspection         | ...
 50036406 | C     | 07/10/2018 | 20    | Cycle Inspection / Reopening Inspection         | ...
 ...      | ...   | ...        | ...   | ...                                             | ...
1 https://www1.nyc.gov/assets/doh/downloads/pdf/rii/restaurant-grading-faq.pdf
Làm sạch dữ liệu trong cơ sở dữ liệu PostgreSQL

Góc nhìn về làm sạch dữ liệu

  • Nhiều cách tiếp cận
  • Cần cân nhắc kỹ
  • Kiến thức miền là then chốt
    • Giá trị nào hợp lệ
    • Lý do trùng lặp
    • Giá trị điền bổ sung phù hợp
Làm sạch dữ liệu trong cơ sở dữ liệu PostgreSQL

Ayo berlatih!

Làm sạch dữ liệu trong cơ sở dữ liệu PostgreSQL

Preparing Video For Download...