จาก ep ที่แล้วที่เราดูตัวอย่าง Machine Learning กับข้อมูลแบบตาราง ใน ep นี้เราจะมาเรียนรู้เรื่องที่จำเป็นในการวิเคราะห์ข้อมูลแบบตาราง นั่นก็คือ Feature Engineering ว่าจะช่วยเพิ่มประสิทธิภาพให้กับโมเดล Deep Neural Network ของเราได้อย่างไร

Feature Engineering

อัลกอริทึมของ Machine Learning จะเรียนรู้จาก Input มาสร้างเป็น Output ในตัว Input จะประกอบด้วย Feature ต่าง ๆ อยู่ในแต่ละ Column อัลกอริทึมจะต้องมองทะลุเข้าไปเรียนรู้ถึง Pattern ที่ซ่อนอยู่ใต้ Feature เหล่านั้น

The iceberg suspected of having sunk the RMS Titanic.
The iceberg suspected of having sunk the RMS Titanic.

Feature Engineering คือ การบวนการใช้ความรู้ Domain Knowledge ในการสร้าง Feature ใหม่ขึ้นมา ตัด Feature ที่ไม่เกี่ยวข้องทิ้งไป เพื่อช่วยทำให้อัลกอริทึมเรียนรู้ได้ดีขึ้น มีวิธีการดังนี้

  1. Imputation เติมข้อมูลที่ขาด (fillna, FillMissing)
  2. Handling Outliers จัดการข้อมูลโดด (replace, Rare)
  3. Binning จับข้อมูลใส่ตะกร้า (cut, qcut)
  4. Log Transform แปลงข้อมูล Exponential เป็น Linear
  5. One-Hot Encoding / Embedding แปลงข้อมูล Category เป็นหลาย Column (Categorify)
  6. Grouping Operations จัดกลุ่มข้อมูล แปลง Row เป็น Column เช่น Pivot Table
  7. Feature Split แตก Column เช่น แตกคำนำหน้า จาก Name (split)
  8. Scaling ทำให้ Mean=0, Std=1 (Normalize, Standardize)
  9. Extracting Date จะอธิบายต่อไป
"Untergang der Titanic", as conceived by Willy Stöwer, 1912
“Untergang der Titanic”, as conceived by Willy Stöwer, 1912

เรามาเริ่มกันเลย

เรื่องราวของเรือ RMS Titanic เป็นเรื่องที่เราทุกคนน่าจะเคยผ่านตา จากการดูหนัง Hollywood กันมาบ้างแล้ว แต่เรื่องจริงที่เกิดขึ้นในประวัติศาสตร์ คือ ในวันที่ 15 เมษายน 1912 เรือไททานิคได้ออกเดินทางภารกิจแรก และชนเข้ากับภูเขาน้ำแข็งจนจมลงสู่ก้นมหาสมุทร คร่าชีวิตผู้คนจำนวน 1,502 ชีวิต จากผู้โดยสารและลูกเรือทั้งหมด 2,224 คน เป็นเหตุการณ์ช็อกโลกในสมัยนั้น ส่งผลให้มีการออกกฏระเบียบเพื่อความปลอดภัยบนเรือให้รัดกุมมากยิ่งขึ้น

View of the bow of the RMS Titanic photographed in June 2004 by the ROV Hercules during an expedition returning to the shipwreck of the Titanic.
View of the bow of the RMS Titanic photographed in June 2004 by the ROV Hercules during an expedition returning to the shipwreck of the Titanic.

เหตุผลหนึ่งที่มีผู้เสียชีวิตมากมายขนาดนี้ เนื่องจากบนเรือ RMS Titanic มีเรือชูชีพไม่เพียงพอสำหรับทุกคน ผู้รอดชีวิตไม่เพียงแต่จะต้องดวงดี ใส่เครื่องรางของขลัง วิ่งเร็วเท่านั้น เพราะว่ามีคนบางกลุ่มบางประเภท ที่มีโอกาสรอดชีวิตมากกว่าคนอื่น เช่น เด็ก สตรี และ ชนชั้นสูง

last lifeboat successfully launched from the Titanic
last lifeboat successfully launched from the Titanic

ในเคสนี้เราจะมาใช้ Machine Learning วิเคราะห์ว่าใครจะเป็นผู้รอดชีวิตจากโศกนาฏกรรมครั้งนี้บ้าง

Open In Colab

Credit

แชร์ให้เพื่อน:

Surapong Kanoktipsatharporn on FacebookSurapong Kanoktipsatharporn on LinkedinSurapong Kanoktipsatharporn on Rss
Surapong Kanoktipsatharporn
Solutions Architect at Bua Labs
The ultimate test of your knowledge is your capacity to convey it to another.

Published by Surapong Kanoktipsatharporn

The ultimate test of your knowledge is your capacity to convey it to another.