ทำไมข้อมูลสูญหายจึงเกิดขึ้น?

Feature Engineering สำหรับ Machine Learning ใน Python

Robert O'Callaghan

Director of Data Science, Ordergroove

สาเหตุที่ทำให้ข้อมูลขาดหาย

  • การเก็บข้อมูลที่ไม่ครบถ้วน
  • ข้อผิดพลาดในการเก็บและจัดการข้อมูล
  • การละเว้นข้อมูลโดยตั้งใจ
  • อาจเกิดจากการแปลงข้อมูล
Feature Engineering สำหรับ Machine Learning ใน Python

ทำไมต้องใส่ใจ?

  • บางโมเดลไม่รองรับข้อมูลที่ขาดหาย (Null/NaN)
  • ข้อมูลที่ขาดหายอาจบ่งชี้ปัญหาข้อมูลในวงกว้าง
  • ข้อมูลที่ขาดหายอาจเป็น feature ที่มีประโยชน์
Feature Engineering สำหรับ Machine Learning ใน Python

การค้นหาข้อมูลที่ขาดหาย

print(df.info())
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 999 entries, 0 to 998
Data columns (total 12 columns):
 #   Column                      Non-Null Count  Dtype  
 --  ------                      --------------  -----  
 0   SurveyDate                  999 non-null    object 
...  ...                         ...             ...
 8   StackOverflowJobsRecommend  487 non-null    float64
 9   VersionControl              999 non-null    object 
 10  Gender                      693 non-null    object 
 11  RawSalary                   665 non-null    object 
dtypes: float64(2), int64(2), object(8)
memory usage: 93.7+ KB
Feature Engineering สำหรับ Machine Learning ใน Python

ตรวจหาค่าที่ขาดหาย

print(df.isnull())
   StackOverflowJobsRecommend  VersionControl  ... \ 
0                        True           False  ...
1                       False           False  ...
2                       False           False  ...
3                        True           False  ...
4                       False           False  ...

   Gender  RawSalary
0   False       True
1   False      False
2    True       True
3   False      False
4   False      False
Feature Engineering สำหรับ Machine Learning ใน Python

ตรวจหาค่าที่ขาดหาย

print(df['StackOverflowJobsRecommend'].isnull().sum())
512
Feature Engineering สำหรับ Machine Learning ใน Python

ตรวจหาค่าที่ไม่ขาดหาย

print(df.notnull())
   StackOverflowJobsRecommend  VersionControl  ... \
0                       False            True  ...
1                        True            True  ...
2                        True            True  ...
3                       False            True  ...
4                        True            True  ...

   Gender  RawSalary
0    True      False
1    True       True
2   False      False
3    True       True
4    True       True
Feature Engineering สำหรับ Machine Learning ใน Python

มาฝึกกันเถอะ!

Feature Engineering สำหรับ Machine Learning ใน Python

Preparing Video For Download...